Project structure:
Start the search: Search keywords here ("big""this")
Search results: Highlight
The database structure required for the project:
==================================================== ===============
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 ?>
searchAndDisplayWithColor.php
1 <?php 2 include 'conn.php'; 3 ?> 4 5
标题:=$row[title]?> 用户:=$row[user] ?> 33 35 | 36
内容:=$row[content]?> | 39
42 发表日期:=$row[lastdate]?>
43 |
44
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]);
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.