Home  >  Article  >  Backend Development  >  Sample code for splitting strings into arrays using the explode() function in PHP

Sample code for splitting strings into arrays using the explode() function in PHP

怪我咯
怪我咯Original
2017-07-07 10:01:041217browse

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(&#39;,&#39;,$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 (&#39;[/.-]&#39;, $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(&#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;

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn