Reputation: 1127
I'm trying to trim away the quotation marks from a PHP variable in CakePHP. I've tried trim()
, substr()
, ereg_replace()
, and str_replace()
, but nothing affects the quotation marks. When I use substr
like this:
substr($comma_separated, 1, -1);
it removes the first and the last letter, but not the quotation marks. The string is
$comma_separated = "[email protected]','[email protected]"
and this is an invalid email address for CakeEmail. I've also tried
$comma_separated = ereg_replace('"', "", $comma_separated);
and
$comma_separated = str_replace('"', '', $comma_separated);
I wasn't specific enough. It's the double quotation marks that I'm trying to remove. Not the single ones.
I've tried all this and they look like the normal quotation marks $comma_separated = ereg_replace('"', "", $comma_separated); //no change in output $comma_separated = str_replace('"', '', $comma_separated); //no change in output $comma_separated = substr($comma_separated,1,-1); //outputs the last and first letter removed $comma_separated = trim($comma_separated,'"'); //no change in output
Upvotes: 0
Views: 2142
Reputation: 862
try this please :
$comma_separated = str_replace('\'', '', $comma_separated);
Upvotes: 0
Reputation: 227190
Your str_replace
isn't working because you are searching for the wrong quotation marks. Your string has single quotes, so why are you searching for double quotes?
$comma_separated = str_replace("'", '', $comma_separated);
You can use this to remove all the quotes from the string.
Upvotes: 2