PHP notes excerpt)

Source: Internet
Author: User
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.
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.