Home >Backend Development >PHP Tutorial >Example of php using explode function to split string into array

Example of php using explode function to split string into array

黄舟
黄舟Original
2017-11-14 13:23:521621browse

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

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 difference between the explode() function and strtok() function in php


Detailed explanation of the application of explode() function in php


explode() function in php Example code


Detailed explanation of the definition of explode() function in php

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!

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