Home > php教程 > php手册 > body text

php开发_多关键字,高亮显示 - jerrylsxu

WBOY
Release: 2016-05-20 11:54:41
Original
1340 people have browsed it

项目结构:

开始搜索:   这里搜索关键字("大""这")

搜索结果:  高亮显示

项目所需数据库结构:

================================================================

                         实现代码:

================================================================

conn.php

1 <?php 2 $conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
3 mysql_select_db("form", $conn);
4 mysql_query("set names 'gbk'"); 
5 ?>
Copy after login

searchAndDisplayWithColor.php

复制代码
 1 <?php 2 include 'conn.php';
 3 ?>
 4 
 5 
Copy after login
6 7 8 10 11 12
关键字: 9
13 14 16 $key[0]", $row[title]); 26 $row[title]=preg_replace("/$key[0]/i", "$key[1]", $row[title]); 27 $row[content]=preg_replace("/$key[0]/i", "$key[0]", $row[content]); 28 $row[content]=preg_replace("/$key[1]/i", "$key[1]", $row[content]); 29 ?> 30 31 32 36 37 38 39 40 41 44 45 48
标题:=$row[title]?> 用户:=$row[user] ?> 33
编辑  |  删除
35
内容:=$row[content]?>
42
发表日期:=$row[lastdate]?>
43
复制代码

说明:在这个小程序中,有一点不足之处在于,只能同时搜索两个关键字,并且中间用空格" "隔开,如果只是搜索一个关键字,如:"大"
显示的时候会出现乱码 ……^|_|^,这是由于下面代码的结果:

1 //用空格符把关键字分割开
2 $key=explode(' ', $_GET[keyWord]);
Copy after login

如果要改进的话,在这里的后面就要做一下判断了。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template