duandou9931 2014-08-24 10:55
浏览 49
已采纳

Php使用preg_replace - 字符编码问题突出显示搜索词

Hy guys, I need to highlight some searched words, in the result, and i was thinking to use pre_replace, and it works just fine, until i use accented characters.

So this is my code:

preg_replace("/(?<!\[)(\b{$search}\b)(?!\])/i", $replace, $string);

And if I'm looking for the word "mokus", it finds it, but leaves out "mókus",

The same thing happens the other way around.

And ideas? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dongyi1015 2014-08-24 12:10
    关注

    You might want to research the term Accent Folding.

    Here's a good article to understand the problem, the proposed solutions are in Javascript but you can translate the logic to PHP

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部