Our practice is to put the search results out, with the search keyword the same as the replacement Cheng Gaoliang Word, we will use the Str_replace (' You find the keyword ', " <带有高亮的html标签> <带有高亮的html标签> The key word you're looking for ", $STR);
Search keywords in the station to lighten the method
Our practice is to put the search results out, with the same search terms as the replacement Cheng Gaoliang Word,
We'll use the Str_replace (' keywords you're looking for ', ' keywords <带有高亮的html标签> you're looking for ', $STR);
It's so easy, okay. Let's take a look at an example.
First, create a database Tutorial "Searchkey";
CREATE TABLE again
CREATE TABLE ' fangke_cc '. ' Search ' (
' ID ' INT (4) Not NULL auto_increment,
' keyword ' VARCHAR (not NULL),
PRIMARY KEY (' id ')
) ENGINE = MYISAM
We import some data
INSERT into ' search ' (' id ', ' keyword ') VALUES
(1, ' China Web first station www.bkjia.com '),
(2, ' China Web first station www.bkjia.com '),
(3, ' China Web first station www.bkjia.com '),
(4, ' China Web first station www.bkjia.com ');
All right, here we go. Perform query operations
*/
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 ']), '
';
}
/*
China Web First station www. 111CN. Net
China Web First station www. 111CN. Net
China Web First station www. 111CN. Net
China web first Station
*/
}
?>
Note: This article original in www.bkjia.com reprint annotated source
http://www.bkjia.com/PHPjc/444964.html www.bkjia.com true http://www.bkjia.com/PHPjc/444964.html techarticle our practice is to put the search results out, with the search keyword the same replacement Cheng Gaoliang Word, we will use the Str_replace (' You find the keyword ', "You find the keyword", $str) ...