Home  >  Article  >  Backend Development  >  Learn to use the explode function to split strings into arrays in PHP

Learn to use the explode function to split strings into arrays in PHP

coldplay.xixi
coldplay.xixiforward
2020-07-27 16:55:102230browse

Learn to use the explode function to split strings into arrays in PHP

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(&#39;,&#39;,$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 (&#39;[/.-]&#39;, $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(&#39;,&#39;,$keyword); 
for($index=0;$index<count($keyarr);$index++) 
{ 
$whereSql .= " And (arc.title like &#39;%$keyarr[$index]%&#39; Or arc.keywords like &#39;%$keyarr[$index]%&#39;) ";
} 
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!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete