php将文中关键词高亮显示,可以用正则表达式
$text = "Sample sentence from AnsonCheung.tk, regular expression has become popular in web programming. Now we learn regex. According to wikipedia, Regular expressions (abbreviated as regex or regexp, with plural forms regexes, regexps, or regexen) are written in a formal language that can be interpreted by a regular expression processor"; $text = preg_replace("/(regex)/i", '<span style="background:#5fc9f6">1</span>', $text); echo $text;
结果: