How to Enable Keyword brightening in the php site. Php site keyword brightening implementation method this article mainly introduces the php site keyword brightening implementation method, detailed analysis of database table creation in the form of instances and how to enable keyword brightening in the php Site
This article mainly introduces how to enable keyword brightening in the php site. it analyzes in detail the creation of database tables and How to Enable Keyword Highlighting for databases in the form of instances, it is very practical. For more information, see
This example describes how to enable keyword brightening in the php site. Share it with you for your reference. The specific analysis is as follows:
This is to replace the search results with the highlighted words in the same way as the search keywords. we will use str_replace (the keyword you are looking, <带有高亮的html标签> Keyword you are looking for, $ str );
This is so easy. now let's look at an instance.
First create a database: create database 'searchkey ';
Create a table again. The SQL database creation code is as follows:
The code is as follows:
Create table 'fangke _ CC'. 'search '(
'Id' INT (4) not null AUTO_INCREMENT,
'Keyword' VARCHAR (20) not null,
Primary key ('id ')
) ENGINE = MYISAM
The SQL database creation code is as follows:
The code is as follows:
Insert into 'search' ('id', 'keyword') VALUES
(1, 'First stop of Chinese scripting programming www.jb51.net '),
(2, 'First stop of Chinese script programming www.jb51.net '),
(3, 'First stop of Chinese script programming www.jb51.net '),
(4, 'First stop of Chinese script programming www.jb51.net ');
Now let's perform the query operation. the instance code is as follows:
The code is as follows:
If ($ _ POST ){
$ Db = 'fangke _ CC ';
Mysql_pconnect ('localhost', 'root', 'root') or die (mysql_error ());
Mysql_select_db ($ db );
Mysql_query ("set names 'gbk '");
$ Key = $ _ POST ['keyword'];
$ SQL = "Select * from search where keyword like '% $ key % '";
$ Query = mysql_query ($ SQL );
While ($ rs = mysql_fetch_array ($ query ))
{
Echo str_replace ($ key ,"$ Key", $ Rs ['keyword']),'
';
}
}
?>
I hope this article will help you with php programming.
This article introduces how to enable keyword brightening in the php site, and analyzes in detail the creation of database tables in the form of instances...