Reputation: 163
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.
Upvotes: 0
Views: 163
Reputation: 322
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.
Upvotes: 0
Reputation: 3397
You can use substr()
to remove "=20" at the end of your string like.
$name = substr($name, 0, -3);
http://php.net/manual/fr/function.substr.php
Upvotes: 2