Home > Backend Development > PHP Tutorial > How to split string into delimited array in php

How to split string into delimited array in php

不言
Release: 2023-04-05 11:56:02
Original
4464 people have browsed it

When we use PHP programming, we sometimes need to separate strings into arrays using delimiters, so in this article we will introduce how to split strings into arrays with delimiters in PHP. Let’s do this Look at the specific content.

How to split string into delimited array in php

#How to split string into delimited array in php's explode function can split a string into an array using delimiters.

Let’s take a look at the basic syntax of the explode function

$myArray =explode(',', $myString);
Copy after login

Let’s take a look at a specific example

Create a How to split string into delimited array in php file and write the following code.

In this sample code we use comma (,) as the separator. Of course you can also use any other delimiter, such as colon (:), semi-colon (;), slash (/), etc.

The code is as follows

<?How to split string into delimited array in php

$myString = "101,How to split string into delimited array in php,xxx@163.com,China";
$myArray = explode(&#39;,&#39;, $myString);
echo "<pre class="brush:php;toolbar:false">";
print_r($myArray);

?>
Copy after login

Accessing the file in a web browser, we will get the following results.

Output result:

Array
(
    [0] => 101
    [1] => How to split string into delimited array in php
    [2] => xxx@163.com
    [3] => China
)
Copy after login

This article has ended here. For more other exciting content, you can pay attention to the relevant column tutorials on the How to split string into delimited array in php Chinese website! ! !

The above is the detailed content of How to split string into delimited array in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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