如果我执行以下代码:
$string = 'This is “Bob” Batman.';
echo $string . '<br>';
$string = preg_replace('/(["“”„]Bob["“„])/', '-$1-', $string);
echo $string;
那么结果就是
This is “Bob” Batman.
This is �-�Bob�-�� Batman.
为什么最后一行不只是这样:
This is -“Bob”- Batman.
最佳答案
这是一个格式问题。
您可以使用正则表达式 u
标志来解决您的问题:
$string = preg_replace('/(["“”„]Bob["“”„])/u', '-$1-', $string);
关于php - preg_replace 用奇怪的字符替换引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49883967/