Copy code The 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 '%$keyarr[$index]%') ";
}
echo $whereSql;
In order to support both spaces and commas, It needs to be replaced with a unified comma in advance, that is, first replace all spaces with commas, then split the string by commas, and then splice the SQL query statement in a loop.
str_replace is the commonly used string replacement function in php.
explode is a function commonly used in PHP to split strings into arrays.
http://www.bkjia.com/PHPjc/765722.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/765722.htmlTechArticleCopy the code as follows: ?php $keyword="asp php,jsp"; $keyword=str_replace(" " ," ",$keyword); $keyword=str_replace(" ",",",$keyword); $keyarr=explode(',',$keyword); for($index=0;...