php给一组指定关键词添加span标签的方法,span标签_PHP教程
程序员文章站
2022-04-17 18:22:34
...
php给一组指定关键词添加span标签的方法,span标签
本文实例讲述了php给一组指定关键词添加span标签的方法。分享给大家供大家参考。具体如下:
这里是php给一组指定的关键词添加span标签,高亮突出显示关键词
// Example use: $spanned = codeWords($string_containing_keywords); // My site: andrew.dx.am // Using colour==blue, but different arrays of words and different // colours can be added. function onlyWholeWords(&$value, $key) { // Ignores words after // comment delimiters. //$value = "/\b(" . $value . ")\b/"; // doesn't handle comments //$value = "/^(?:(?!\/\/).)*\K\b(" . $value . ")\b/"; // \K lookbehind alternative is not supported in PHP " . $value . "