Home >Backend Development >PHP Tutorial >Example of php using explode function to split string into array
I believe everyone knows that explode() function in php is to split the string into array . Its return value is to return an array composed of strings, so today we will introduce to you an example of how to use the explode function to split a string into an array!
Use the explode function to split the string into an array
<?php $source = "hello1,hello2,hello3,hello4,hello5";//按逗号分离字符串 $hello = explode(',',$source); for($index=0;$index<count($hello);$index++) { echo $hello[$index];echo "</br>"; } ?
split function to split characters
The separator can be slash, dot, Or horizontal line
<?php $date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />\n"; ?>
Realize multiple conditions through arraysQuery's code
<?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;
Summary:
Through the study of this article, everyone has a certain understanding of how to use the explode function to split a string into an array. I hope it will be helpful to your work!
Related recommendations:
The above is the detailed content of Example of php using explode function to split string into array. For more information, please follow other related articles on the PHP Chinese website!