Home > Article > Backend Development > Teach you step by step how to do keyword matching project (search engine)----On the first day, teach you how to do it----_PHP tutorial
The first day
Received requirements, the requirements are as follows:
1. Collect keywords and build a keyword database.
After receiving this task, my first thought was, isn’t this simple? Start immediately to create a keyword entry interface and save it to the database. The first step was completed, and I laughed all day long. I didn’t expect that things turned out to be so simple.
Database configuration file: config.php
<span>$database_host</span> = 192.168.1.1 <span>$database_user</span> =<span> xiaoshuaishuai </span><span>$database_password</span> =<span> xiaoshuaishuai </span><span>$database_charset</span> = "utf-8"
Backend logic processing: keywords.php
<?<span>php </span><span>include</span> "config.php" <span>$keywords</span> = <span>$_REQUEST</span>["keywords"<span>]; </span><span>$con</span> = <span>mysql_connect</span>(<span>$database_host</span>,<span>$database_user</span>,<span>$database_password</span><span>); </span><span>mysql_query</span>("SET NAMES '<span>$database_charset</span>'",<span>$conn</span><span>); </span><span>mysql_select_db</span>("dict",<span>$conn</span><span>); </span><span>foreach</span>(<span>$keywords</span> <span>as</span> <span>$keyword</span><span>){ </span><span>//</span><span>save $keyword to database</span> <span>$sql</span> = "insert into keywords(word) values ('<span>$keyword</span>')"<span>; </span><span>mysql_query</span>(<span>$sql</span>,<span>$conn</span><span>); } </span><span>mysql_close</span>(<span>$conn</span>);
Currently, Baidu promotion has three matching methods: precise, phrase, and broad. Generally speaking, the golden combination matching method is: broad matching + search term report + negative keywords. In terms of traffic, it's broad>phrase>accurate. You can set it according to your actual situation!
If you want an exact match, you need to put quotes around ABC.