Home > Backend Development > PHP Tutorial > 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

怪我咯
Release: 2023-03-13 06:36:01
Original
1277 people have browsed it

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>"; 
} 
?>
Copy after login

//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"; 
?>
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template