我有包含值,如"hello world\' hello world\'"
一个字符串,我想摆脱转义字符的摆脱转义字符在PHP
我试过下面的代码(反斜线。):
str_replace("\\", "", $data);
但它似乎没有工作。
我有包含值,如"hello world\' hello world\'"
一个字符串,我想摆脱转义字符的摆脱转义字符在PHP
我试过下面的代码(反斜线。):
str_replace("\\", "", $data);
但它似乎没有工作。
如果你想要做的就是摆脱反斜杠,那么就认为完成只是
$var = stripslashes($var);
假设您使用$ var作为str_replace()中的最后一个参数而不是$ data,它应该可以正常工作。
$var = "hello world\' hello world\'";
echo $var . "<br />";
echo str_replace("\\", "", $var) . "<br />";
输出:
hello world\' hello world\'
hello world' hello world'
这应该工作一个非常方便的PHP函数非常适合你你没有在php中正确地引用变量$ var替换主题参数,假设你需要替换\'你正在放入\ \搜索它,因此没有发现被替换的跳e这有助于帮助
$var = "hello world\' hello world\'";
echo str_replace("\'","",$var);
您想要做的第一件事是什么? – 2012-01-14 20:20:10
'str_replace'返回结果。你把它分配给任何东西吗? – takteek 2012-01-14 20:21:06
我敢打赌[描述行为@takteek提到的作品]的[精细的php手册条目](http://php.net/manual/en/function.str-replace.php)。在询问为什么某些东西不起作用或者你会得到像我这样对你大喊大叫的A-hole之前,总是先咨询PHP文档:) – rdlowrey 2012-01-14 20:23:18