问题
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);
回答1:
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);
回答2:
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);
回答3:
This should work:
str_replace("'",'"',$text);
回答4:
$page = str_replace("'", "\"", $page);
回答5:
I think you should do replacements with preg_replace();
$str = "'Here 'it' goes'";
echo preg_replace("/'/", '"', $str);
回答6:
This works. You actually don't need any escaping character.
$page = str_replace("'", '"', $page);
回答7:
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);
来源:https://stackoverflow.com/questions/10200127/php-string-replace-quotes