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

mysql-php matching string changes color after search

WBOY
WBOYOriginal
2016-10-17 09:30:151177browse

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>

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

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