Home > Backend Development > PHP Tutorial > mysql-php matching string changes color after search

mysql-php matching string changes color after search

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-10-17 09:30:15
Original
1209 people have browsed it

How to make PHP search for mysql and change the color of matching strings?

For example, search 123

Assuming that it matches 123: 09148

1234097

It will change like this

Reply content:

How to make PHP search for mysql and change the color of matching strings?


For example, search 123

Assuming that it matches 123: 09148

1234097 It will change like this

Regular replacement, html tag + css

<code class="php">$keyword = yourobj->yourmethod();
$pattern = "/$keyword/i";
$replacement = "<span class='hl'>$keyword</span>";
echo preg_replace($pattern, $replacement, $keyword);</code>
Copy after login

The general idea is to find the keyword and add a style.

Related labels:
source:php.cn
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
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
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