这有效:
echo preg_replace("/TesT/i","<b>FOUND</b>","TEST"); // works as expected prints FOUND
为什么以下不起作用?在我的项目中,我想突出显示搜索结果,无论案例/写入搜索输入
echo preg_replace("/üöÄ/i","<b>FOUND</b>","ÜÖÄ"); // does NOT work as expected prints ÜÖÄ
我也尝试了以下内容,但也无效:
mb_internal_encoding("UTF-8");
mb_regex_encoding("UTF-8");
mb_ereg_replace("/üöÄ/i","<b>FOUND</b>","ÜÖÄ");
更新:
据我所知,我确保我的页面上的所有内容,脚本,连接都是UTF-8
答案 0 :(得分:2)
您还需要为u
支持传递utf8
选项。
这将有效:
echo preg_replace("/üöÄ/iu","<b>FOUND</b>","ÜÖÄ");
您可以在此处找到可用选项列表:http://php.net/manual/en/reference.pcre.pattern.modifiers.php