PHP notes learning excerpt () if, true, false, return value.
Fuzzy search in SQL statements of php
Fuzzy search is implemented by using the LIKE (case insensitive) keyword. The LIKE condition is generally used to search for a field. the fuzzy search function is implemented through the "%" or "_" wildcard, wildcard characters can either be placed before or before a field. Fuzzy search cannot be implemented only through LIKE, so the role of wildcards cannot be ignored.
The following are three instances:
Search starts with PHP:
SELECT * FROM table WHERE title LIKE 'php %'
The search ends with PHP:
SELECT * FROM table WHERE title LIKE '% php'
Search for PHP100:
SELECT * FROM table WHERE title LIKE '% PHP %'
Note: % indicates a string consisting of 0 or more characters. _ indicates a single character, similar to the role of metacharacters in regular expressions.
You can add other conditions after LIKE, similar to the if statement.
Content in the example database
[Php] view plain copy
Echo "$ r [content]"."
";}}?>
Search for php
II. Principles and skills for searching multiple keywords
To search for a single keyword, click submit Form> accept keyword in php file> execute SQL> output result
If multiple keywords are used: multiple keywords are separated by spaces or + signs when submitting a form. after receiving the submitted string from the PHP file, you can use some functions such: the sort E function splits the string into multiple keywords and stores them in the array. then, you can obtain the desired content through multiple LIKE fuzzy searches in the database.
3. replacing keywords for highlighted display
After obtaining the desired content through fuzzy search, use a regular expression to replace the content to be searched. you can change the display effect by changing the color, bold, and so on.
[Php] view plain copy
\ 1", $ R [content]); $ r [content] = preg_replace ("/($ k [1])/I ","
\ 1", $ R [content]); echo" $ r [content] "."
";}}?>
Of course, I am familiar with PHP and want to practice more code. PHP also has many integrated development environments and can implement many software projects.