Home > Article > Backend Development > mysql-php matching string changes color after search
How to make PHP search for mysql and change the color of matching strings?
Assuming that it matches 123: 09148
1234097
It will change like thisReply content:
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.