This article mainly introduces the use of explodefunctionsplitstringintoarray in php. Friends who need it can refer to it.
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>"; } ?>
//The split function performs character processing Split
// The delimiter can be a slash, dot, or horizontal line
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"; ?>
Multiple conditions are implemented through arraysQuery Code
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;
The above is the detailed content of Sample code for splitting strings into arrays using the explode() function in PHP. For more information, please follow other related articles on the PHP Chinese website!