Split the string
//Use the explode function to split the string into an array
The code is as follows:
<?php $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串 $hello = explode(',',$source); for($index=0;$index<count($hello);$index++) { echo $hello[$index];echo "</br>"; } ?> //split函数进行字符分割 // 分隔符可以是斜线,点,或横线
The code is as follows:
<?php $date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>
The code to implement multi-condition query through arrays
The code is as follows:
<?php $keyword="asp php,jsp"; $keyword=str_replace(" "," ",$keyword); $keyword=str_replace(" ",",",$keyword); $keyarr=explode(',',$keyword); for($index=0;$index<count($keyarr);$index++) { $whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') "; } echo $whereSql;
Related learning recommendations: PHP programming from Beginner to master
The above is the detailed content of Learn to use the explode function to split strings into arrays in PHP. For more information, please follow other related articles on the PHP Chinese website!