我尝试突出显示所有单词匹配,例如
示例:输入是đã
然后所有单词将被突出显示đã đà Đà Đã
但只是đã
亮点。
这是我的完整代码
<?php
header( 'Content-Type: text/html; charset=UTF-8' );
function highlightWords($text, $words) {
$text = preg_replace("|($words)|Ui", "<span class=\"highlight_word\">$1</span>", $text);
return $text;
}
$string = 'đã đà Đà Đã';
$words = 'đã';
$string = highlightWords($string, $words);
?>
<html>
<head>
<title>PHPRO Highlight Search Words</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
.highlight_word{
background-color: yellow;
}
</style>
</head>
<body>
<?php echo $string; ?>
</body>
</html>
如何突出显示所有单词(utf-8)匹配(例如示例)谢谢。