替换php中的多个utf-8字符
我有一个包含多个 utf-8 字符的字符串,如下所示
\u00b4, \u2019, \u201b, \u2032
我想将它们替换为以下 html 字符
'
我正在使用以下 php 代码来替换这些字符
$search = "(\\u00b4|\\u2019|\\u201b|\\u2032)";
$replace = "'";
$result = preg_replace($search, $replace, $string);
我不断收到以下警告,并且 $result 为 null
Warning: preg_replace(): Compilation failed: PCRE does not support \\L, \\l, \\N, \\U, or \\u at offset 2 in /...
我没有知道该怎么做。任何有关如何继续替换这些 utf8 字符的想法都将受到赞赏!
I have a string with multiple utf-8 characters that look like this
\u00b4, \u2019, \u201b, \u2032
I want to replace these with the following html character
'
I'm using the following php code to replace these
$search = "(\\u00b4|\\u2019|\\u201b|\\u2032)";
$replace = "'";
$result = preg_replace($search, $replace, $string);
I keep getting the following warning, and $result is null
Warning: preg_replace(): Compilation failed: PCRE does not support \\L, \\l, \\N, \\U, or \\u at offset 2 in /...
I have no idea what to do. Any ideas on how to proceed with replacing these utf8 characters is appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当对特定字符代码进行 preg 匹配时,您需要使用 \x 十六进制表示法,而不是 unicode 表示法 - 这些看起来像 unicode 值。
When doing a preg match on specific character codes, you need to use the \x hexadecimal notation, not unicode notation -- those look like unicode values.
您没有正确转义反斜杠,您需要 2 个额外的反斜杠:
You didn't escape the backslashes correctly, you need 2 extra backslashes: