项目结构:498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' height="183" alt="" width="274" src="/uploadfile/201301/2/94195822133.png" />开始搜索: 这里搜索关键字("大""这")498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' height="269" alt="" width="640" src="/uploadfile/201301/2/99195822339.png" />搜索结果: 高亮显示498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' height="480" alt="" width="565" src="/uploadfile/201301/2/54195822477.png" />项目所需数据库结构:498)this.width=498;'' onmousewheel = ''javascript:return big(this)'' height="187" alt="" width="640" src="/uploadfile/201301/2/07195822299.png" />实现代码:conn.php<?php $conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误"); mysql_select_db("form", $conn); mysql_query("set names ''gbk''"); ?> searchAndDisplayWithColor.php <?php include ''conn.php''; ?> <table width=500 align="center"> <form action="" method="get"> <tr> <td>关键字:<input type="text" name="keyWord" /> <input type="submit" value="搜索" /></td> </tr> </form> </table> <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef"> <?php //关键字不为空的时候才执行相关搜索 if(
看PHP如何实现多关键字加亮 _网学
浏览:
GET[''keyWord'']){ //用空格符把关键字分割开 $key=explode('' '',
看PHP如何实现多关键字加亮 _网学
浏览:
GET[keyWord]); $sql="select * from 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)){ //替换关键字,并且把关键字高亮显示 $row[title]=preg_replace("/$key[0]/i", "<font color=red><b>$key[0]