Reputation: 2711
Hello I am trying to get all single quotes to be double quotes using the php str_replace however it does not seem to be working no matter what I do, suggestions
$page = str_replace("/'/", '/"/', $page);
Upvotes: 3
Views: 37083
Reputation: 15683
Update: I'd agree with others that the following is an easier-to-read alternative for most folks:
$page = str_replace("'", '"', $page);
My original answer:
$page = str_replace(chr(39), chr(34), $page);
Upvotes: 21
Reputation: 18795
You only need the start and end /
for preg_...()
(and other regex) functions. For basic functions such as str_replace
, simply use the characters:
str_replace("'", '"', $text);
Upvotes: 0
Reputation: 490607
You don't need to escape the quote character (in fact it is \
, not /
, unless you were confused with the standard regex delimiters) if the string isn't delimited with the same character.
$page = str_replace("'", '"', $page);
Upvotes: 4
Reputation: 669
This works. You actually don't need any escaping character.
$page = str_replace("'", '"', $page);
Upvotes: 0
Reputation: 4888
I think you should do replacements with preg_replace();
$str = "'Here 'it' goes'";
echo preg_replace("/'/", '"', $str);
Upvotes: 0