php搜索关键字 高亮
来源:互联网 发布:手机载图软件 编辑:程序博客网 时间:2024/06/06 08:33
<?php
$conn=@mysql_connect("localhost","root","") or die ("链接失败");
mysql_select_db("gxt",$conn);
mysql_query("set names 'utf8'");
//全站搜索
// if($_GET[key]){
// $sql="select * from poetry where content like'%$_GET[key]%'";
// $res=mysql_query($sql,$conn);
// while($row=mysql_fetch_array($res)){
// //关键字 高亮度
// $row[content]=preg_replace("/$_GET[key]/i", "<font color=red> <b>\\0</b></font>", $row[content]);
// echo "$row[content].<br>";
// }
// }
// 多关键字搜索
if($_GET[key]){
$k=explode(" ", $_GET[key]);
$sql="select * from poetry where content like'%$k[0]%' and content like'%$k[1]%'";
$res=mysql_query($sql,$conn);
while($row=mysql_fetch_array($res)){
//关键字 高亮度
$row[content]=preg_replace("/($k[0])/i", "<font color=red> <b>\\0</b></font>", $row[content]);
$row[content]=preg_replace("/($k[1])/i", "<font color=red> <b>\\0</b></font>", $row[content]);
echo "$row[content]"."<br>";
}
}
?>
<form action="" method="get">
关键字:
<input type="text" name="key"/>
<input type="submit" name="sub" value="全站搜索"/>
</form>
$conn=@mysql_connect("localhost","root","") or die ("链接失败");
mysql_select_db("gxt",$conn);
mysql_query("set names 'utf8'");
//全站搜索
// if($_GET[key]){
// $sql="select * from poetry where content like'%$_GET[key]%'";
// $res=mysql_query($sql,$conn);
// while($row=mysql_fetch_array($res)){
// //关键字 高亮度
// $row[content]=preg_replace("/$_GET[key]/i", "<font color=red> <b>\\0</b></font>", $row[content]);
// echo "$row[content].<br>";
// }
// }
// 多关键字搜索
if($_GET[key]){
$k=explode(" ", $_GET[key]);
$sql="select * from poetry where content like'%$k[0]%' and content like'%$k[1]%'";
$res=mysql_query($sql,$conn);
while($row=mysql_fetch_array($res)){
//关键字 高亮度
$row[content]=preg_replace("/($k[0])/i", "<font color=red> <b>\\0</b></font>", $row[content]);
$row[content]=preg_replace("/($k[1])/i", "<font color=red> <b>\\0</b></font>", $row[content]);
echo "$row[content]"."<br>";
}
}
?>
<form action="" method="get">
关键字:
<input type="text" name="key"/>
<input type="submit" name="sub" value="全站搜索"/>
</form>
0 0
- php搜索关键字 高亮
- 搜索关键字高亮
- 搜索 和 关键字高亮
- 设置搜索关键字高亮
- 搜索关键字显示高亮
- 页面高亮显示搜索关键字
- 搜索关键字高亮显示方法
- 搜索关键字高亮显示方法
- js+正文规则 高亮搜索关键字
- Android ListView 搜索关键字高亮显示
- WPF搜索关键字高亮显示
- Lucene+HighLighter 搜索关键字高亮显示
- jquery高亮显示搜索的关键字
- android中搜索关键字高亮
- 截取关键字高亮作为搜索结果
- js RegExp 搜索并高亮关键字
- 搜索关键字高亮及复制粘贴
- android中搜索关键字高亮
- python enumerate 用法小结
- 【2049】字符个数
- POJ3751 时间日期格式转换
- knowledge generalization
- 巴什博奕类型取石子
- php搜索关键字 高亮
- LintCode_156 Merge Intervals
- 带修改的莫队算法学习小记
- 航班信息查询和检索系统-数据结构课程设计
- 为什么使用存储过程
- 【2050】特殊质数
- SQL Server对文件访问的权限
- idea 破解方法
- Adapter模版