Site search Keywords Lighten method _php Tutorial

Source: Internet
Author: User
Tags mysql tutorial
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) ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.