![](/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.