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

How to split string into delimited array in php

不言
不言Original
2019-02-25 11:42:514422browse

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);

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);

?>

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
)

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!

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