Php site keyword brightening Implementation Method

Source: Internet
Author: User

Php site keyword brightening Implementation Method

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, <with highlighted html tags> 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, "<B> $ key </B>", $ rs ['keyword']), '<br/> ';
}
}

?>
<Form name = "form1" method = "post" action = "">
<Label>
<Input name = "keyword" type = "text" id = "keyword">
</Label>
<Label>
<Input type = "submit" name = "Submit" value = "submit">
</Label>
</Form>

 

I hope this article will help you with php programming.

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.