我想用奇数" "
"更改字符串,例如:
:
<>之前他说:"我不这么认为。"之前我当前的代码是:
$sentence = addslashes(preg_replace('/^'"';$/',''"',$var));
我在代码中的问题是什么?
^
和$
将只匹配整个字符串的开始和结束(或/m
模式下的整行)。由于"
不像那样出现,您的正则表达式完全匹配它。只要去掉^
和$
就可以了。
顺便说一句,也许你想用html_entity_decode()
代替。
您最好使用PHPs htmlspecialchars_decode()
:
$var = "He said: "I don't think so"";
$sentence = htmlspecialchars_decode($var);
这个可以解决你的问题:
$yourstring = "He said: "I don't think so"";
$newstring = str_replace(""","'"",$yourstring);
echo $newstring;