doulangpeng3933 2013-09-24 22:37
浏览 9
已采纳

如何从字符串中删除这个额外的字符?

I have a string that is stored in an array, and eventually inserted into a SQL database using php and PDO. When I look in the database there is an =20 that gets stored at the end of the string that I would like to get rid of.

My code looks something like this:

$name = trim($message_item[1]);
$name = addslashes($name);
$so_row = "INSERT into sales_order (name) VALUES('$name')";
$dbmrp->exec($so_row);

I thought that trim() would remove anything extra, but it doesn't seem to help. I can get rid of it using preg_replace('/\s+/','',$name), but then I lose all the whitespace, including the ones in the middle that I want to keep. So what is =20 and how do I get rid of it?

more info- $message_item is an array that is created from exploding a string that gets read from an email.

  • 写回答

4条回答 默认 最新

  • dongping1689 2013-09-24 22:55
    关注

    Trim is only for spaces on the beginning and the end of string. You can do as Donovan said and remove all 3 last caracter.

    $name = substr($name, 0, -3);
    

    or replace all =20 by empty

    str_replace('=20', '', subject)
    

    But I really think you should figure out why you are getting an string with this =20. Any solution that remove it, is nothing but an workaround.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图