php string replace quotes

﹥>﹥吖頭↗ 提交于 2019-12-24 09:43:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!