Example of php using explode function to split string into array

黄舟
Release: 2023-03-17 13:28:01
Original
1618 people have browsed it

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

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

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

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!

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