有特殊字符替换字符

问题描述:

我有这样的事情:有特殊字符替换字符

$x = "#frac {2} {3}"; 

我试试这个代码,不过这并不工作:

$x = str_replace("#","\"",$x); 

我想在此字符串与\替换#。但我不能使用str_replace。

有帮助吗?

+0

尝试'$ X = str_replace函数(” # “” \\ “,$ x);' – martindilling 2014-10-30 07:52:29

+0

你正在转义引号而不是反斜杠 – Ghost 2014-10-30 07:53:39

你用替换# “
要你需要转义字符串中使用反斜线。
How do you make a string in PHP with a backslash in it?

$x = "#frac {2} {3}"; 
$x = str_replace("#", "\\", $x);