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!
$unicode = "\u00b4 \u2019 \u201b \u2032";
$unicode = preg_replace('/\\\\u[^ ]+/im', "'\r\n", $unicode);
echo $unicode;
You didn't escape the backslashes correctly, you need 2 extra backslashes:
\\\\
对特定的字符代码进行预匹配时,您需要使用\\ x十六进制表示法,而不是unicode表示法-看起来像unicode值。
$search = "(\xb4|\x2019|\x201b|\x2032)";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.