The method for changing keywords for intra-site search. This is to replace the search result with the highlighted keyword, and we will use str_replace (the keyword you are looking for, "the keyword you are looking for", $ str) this is to replace the search results with the highlighted words in the same way as the search keywords. we will use str_replace ('your search keyword '," <带有高亮的html标签> Keyword you are looking ", $ Str );
Site Search Keyword brightening method
We use this method to replace the search result with the highlighted word, which is the same as the search keyword,
We will use str_replace ('keyword you are looking for '," <带有高亮的html标签> Keyword you are looking ", $ Str );
This is so easy. now let's look at an instance.
First create a database tutorial create database 'searchkey ';
Create a table
Create table 'fangke _ CC'. 'search '(
'Id' INT (4) not null AUTO_INCREMENT,
'Keyword' VARCHAR (20) not null,
Primary key ('id ')
) ENGINE = MYISAM
We import some data
Insert into 'search' ('id', 'keyword') VALUES
(1, 'China WEB first stop www.bkjia.com '),
(2, 'China WEB first stop www.bkjia.com '),
(3, 'China WEB first stop www.bkjia.com '),
(4, 'China WEB first stop www.bkjia.com ');
Now let's perform the query operation.
*/
If ($ _ POST ){
$ Db = 'fangke _ CC ';
Mysql tutorial _ 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']),'
';
}
/*
The first Chinese WEB site www.111cn. Net
The first Chinese WEB site www.111cn. Net
The first Chinese WEB site www.111cn. Net
China WEB first stop
*/
}
?>
Note: This article was originally reproduced on www.bkjia.com and indicated the source
Into, we will use str_replace ('keyword you are looking for ', "keyword you are looking for", $ str )...