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条)

报告相同问题?