PHP implementation of multi-conditional query via array (string segmentation) _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
$keyword = "asp php,jsp";
$keyword =str_replace ("", "", $keyword);
$keyword =str_replace ("", ",", $keyword);
$keyarr =explode (', ', $keyword);
for ($index =0; $index
{
$whereSql. = "and (Arc.title like '% $keyarr [$index]% ' Or arc.keywords like '% $key arr[$index]% ') ";
}
Echo $whereSql;


to support spaces and commas at the same time, you need to replace them with a uniform comma before replacing them with commas, then separating the strings with commas and looping through the SQL query statements. The

Str_replace is a commonly used string substitution function in PHP. The
explode is a function that is commonly used in PHP to divide the array into arrays.

http://www.bkjia.com/phpjc/765722.html www.bkjia.com true Span id= "Isbasedonurl" itemprop= "Isbasedonurl" >http://www.bkjia.com/phpjc/765722.html techarticle Copy code code as follows: PHP $keyword = "asp php , JSP "; $keyword =str_replace ("", "", $keyword); $keyword =str_replace ("", ",", $keyword); $keyarr =explode (', ', $keyword); for ($index =0; ....

  • 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.