![](/img/trans.png)
[英]how to search all words starts match with regular expression character in php?
[英]How to highlight all words in hindi text with regular expression in php?
我正在使用正则表达式的代码
$title = preg_replace("/\b(".preg_quote($searchword).")\b/i", '<span class="highlight_txt">\1</span>', $title);
和
$title = preg_replace("/\w*?".preg_quote($searchword)."\w*/i", "<span class='highlight_txt'>$0</span>", $title);
It is working properly for english but not for hindi string
例如,搜索“ह”看起来像这样
तरहकेलाभमिलतेहैं
我想要结果
तरहकेलाभमिलतेहैं
在英语中它正常工作。 例如,搜索h
印度 领导人
请帮我
\\w
或\\p{L}
与हां的मात्रा部分हैं
。 它只会匹配ह
离开मात्रा无法比拟的。
您可以使用[^\\p{Zs}\\p{P}]
来匹配任何周围的非空格,非标点字符。
/[^\p{Zs}\p{P}]*?ह[^\p{Zs}\p{P}]*/u
修饰符/u
用于unicode支持。
码:
$title = 'तरह के लाभ मिलते हैं';
$searchword = 'ह';
$title = preg_replace('/[^\p{Zs}\p{P}]*?'.preg_quote($searchword).'[^\p{Zs}\p{P}]*/u',
"<span class='highlight_txt'>$0</span>", $title);
//=> <span class='highlight_txt'>तरह</span> के लाभ मिलते <span class='highlight_txt'>हैं</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.