Home  >  Article  >  Backend Development  >  thinkphp keyword highlighting

thinkphp keyword highlighting

WBOY
WBOYOriginal
2016-08-08 09:30:431215browse

First define a function in function.php:

//关键字描红
function keywords_red($string,$keywords=''){
    if(empty($keywords)||empty($string)) return $string;
    return str_replace($keywords,'<span class="red">'.$keywords.'</span>',$string);
}

Then write this in the template variable

{$<pre name="code" class="php">/*
**参数说明
**$sheng为页面输出的变量
**$keywords_red即是描红函数
**###代表第一个参数,即$sheng
**$q代表需要描红的字体,即搜索的关键字
*/

sheng|keywords_red=###,$q}


The above introduces thinkphp keyword tracing, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn