Home  >  Article  >  Backend Development  >  How to replace the search title keyword in php with red color

How to replace the search title keyword in php with red color

藏色散人
藏色散人Original
2020-08-19 10:02:143268browse

php search and replace red implementation method: first open the corresponding PHP file; then search for keywords through the "if(!empty($_GET['kws'])) {...}" method and Just replace all places containing keywords with red fonts.

How to replace the search title keyword in php with red color

Recommended: "PHP Video Tutorial"

php replace the search title keyword with red

//将包含关键字的地方全部替换为红色字体(不区分大小写)
if(!empty($_GET['kws'])) //搜索关键字
{
    $k = trim($_GET['kws']);
    foreach($result as $key =>$value){
        $result[$key][&#39;title&#39;] = str_ireplace($k, "<font color=&#39;red&#39;>$k</font>", $value[&#39;title&#39;]);
    }
}

The above is the detailed content of How to replace the search title keyword in php with red color. For more information, please follow other related articles on the PHP Chinese website!

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