标签:
$sql = "SELECT * FROM `message` WHERE `content`like ‘%$k[0]%‘ and `content`like ‘%$k[0]%‘";
$r[content] = preg_replace("/($_GET[key])/i", "<font color = red><b>\\1</b></font>", $r[content]);
代码实例:
<?php
include("26_mysql_class.php");
header("Content-type:text/html;charset=utf-8");
error_reporting(0);
$db = new mysql(‘localhost‘,‘root‘,‘‘,‘message_board‘,‘utf8‘);
if($_GET[key]){
$k = explode ( " ", $_GET[key]);
$sql = "SELECT * FROM `message` WHERE `content`like ‘%$k[0]%‘ and `content`like ‘%$k[0]%‘";
echo "GET内容:".$_GET[key]."<br>"."<hr>搜索结果<br>";
$q = $db->query($sql);
while ($r = mysql_fetch_array($q)) {
$r[content] = preg_replace("/($k[0])/i", "<font color = red><b>\\1</b></font>", $r[content]);
$r[content] = preg_replace("/($k[1])/i", "<font color = red><b>\\1</b></font>", $r[content]);
echo $r[content]."<br>";
}
}
?>
<form action="" method="get">
关键字:
<input type = "text" name="key"/>
<input type = "submit" name="sub" value="全站搜索"/>
</form>
标签:
原文地址:http://www.cnblogs.com/chenyigen/p/4693342.html