See how PHP implements multi-keyword highlighting
Implementation code:
conn.php
??? ??? $conn = @ mysql_connect ("localhost", "root", "") or Die ("Database link Error");?
??? mysql_select_db ("form", $conn);?
??? mysql_query ("Set names ' GBK '");??
??? ?>
searchanddisplaywithcolor.php
?
?
??? ??? include ' conn.php ';?
??? ?
???
?
??????
????
$key [0]
$key [1]
$key [0]
$key [1]
???????? cellspacing= "1" bgcolor= "#add3ef";????????? ???????? Do you perform related searches when the keyword is not empty????????? if ($_get[' KeyWord ')} {????????? Divide the keyword with a space character????????? $key =explode (', $_get[keyword]);????????? $sql = "SELECT * from the message where title like ' $key [0] ' or title like ' $key [1] ' or content like ' $key [0] ' or content like ' % $key [1]% ' ";????????? $query =mysql_query ($sql);????????? while ($row =mysql_fetch_array ($query)) {????????????? Replace the keyword and highlight the keyword????????????? $row [Title]=preg_replace ("/$key [0]/i", "", $row [title]);????????????? $row [Title]=preg_replace ("/$key [0]/i", "", $row [title]);????????????? $row [Content]=preg_replace ("/$key [0]/i", "", $row [content]);????????????? $row [Content]=preg_replace ("/$key [1]/i", "", $row [content]);????????????? ???????????????
? ????????????
Title: User: ? ???????????? "> Edit |???????????????? href= "delete.php?id= " > delete? ???????????? | ? ????????
? ????????
? ????????????
| Content: | ? ????????
? ????????
? ????????????
? ???????????? Published date: ? ???????????? | ? ????????
? ???????? ???????? }? ???????? ?????
Note: In this small program, a little bit of a disadvantage is that only two keywords can be searched at the same time, and the middle with a space "" separated, if you just search a keyword, such as: "Big"
The display will appear garbled ... ^|_|^, this is due to the result of the following code:
???? Divide the keyword with a space character?
???? $key =explode (', $_get[keyword]);
If we want to improve, we should make a judgment in the back of this place.