Home > Backend Development > PHP Tutorial > PHP development_multiple keywords, highlighting

PHP development_multiple keywords, highlighting

WBOY
Release: 2016-07-29 08:56:13
Original
1134 people have browsed it

Project structure:

PHP development_multiple keywords, highlighting

Start the search: Search keywords here ("big""this")

PHP development_multiple keywords, highlighting

Search results: Highlight

PHP development_multiple keywords, highlighting

The database structure required for the project:

PHP development_multiple keywords, highlighting

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

                                                                                            Implementation code:

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

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

PHP development_multiple keywords, highlighting

 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

PHP development_multiple keywords, highlighting

Note: In this small program, one shortcoming is that you can only search for two keywords at the same time, and they are separated by a space " ". If you just search A keyword, such as: "big"
will appear garbled when displayed... ^|_|^, this is the result of the following code:

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

If you want to improve it, you need to do it later here Judged.

The above introduces PHP development_multiple keywords, highlighted, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template