: This article mainly introduces the php fuzzy search instance code. if you are interested in the PHP Tutorial, refer to it. Header ("content-type: text/html; charset = utf-8 ");
// Obtain user data
$ Keywords = $ _ POST ['keyword'];
//
Connect to database
$ C or die ('database link failed ');
// Select the database and set the character set
Mysql_select_db ('search ');
Mysql_set_charset ('utf8 ');
// Php fuzzy search
If (empty ($ keywords )){
$ Str = "Enter the content to be queried ";
} Else {
$ SQL = "SELECT * FROM user WHERE username LIKE '% $ keywords % '";
}
$ Rs = mysql_query ($ SQL );
$ Users = array ();
While ($ row = mysql_fetch_assoc ($ rs )){
// Highlight replacement
$ Row ['username'] = str_replace ($ keywords, ''. $ keywords.'', $ row ['username']);
$ Users [] = $ row;
}
// Print_r ($ users );
?>
Php fuzzy search
User query with php fuzzy queryer
If ($ keywords ){
Echo 'query keyword '. $ keywords.' The result is :';
If ($ users ){
Echo"
";Echo"
| UID |
User name |
Gender |
Email |
Hobbies |
";Foreach ($ users as $ key => $ value ){Echo"
";Echo"
| ". $ Value ['uid']." | ";Echo"
". $ Value ['username']." | ";Echo"
". $ Value ['sex']." | ";Echo"
". $ Value ['email ']." | ";Echo"
". $ Value ['hobby']." | ";Echo"
";}Echo"
";
} Else {
Echo "no related users found ";
}
} Else {
Echo "". $ str ."
";
}
?>
The above introduces the php fuzzy query instance code, including the content, and hope to be helpful to friends who are interested in PHP tutorials.