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

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

藏色散人
Release: 2023-03-04 18:38:02
Original
3374 people have browsed it

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;]);
    }
}
Copy after login

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!

Related labels:
php
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template