Home >Backend Development >PHP Tutorial >PHP method to split specified characters into arrays

PHP method to split specified characters into arrays

小云云
小云云Original
2018-03-14 09:27:001949browse

This article mainly shares with you a PHP method of dividing specified characters in a string into arrays. It has a good reference value. I hope it will be helpful to everyone. I hope it can help everyone.

The example is as follows:


<?php
$str="1|2|3|4|5|";
$var=explode("|",$str);
print_r($var);
?>
$var=explode("|",$str);

Split $str by |

php has other ways to split specified characters in a string into arrays


str_split(string,length)

Parameter description

string required. Specifies the string to be split.

length Optional. Specifies the length of each array element. The default is 1.

json_decode() This function can also split the string into an array (the second parameter is true)

Related recommendations:

Summary of character splitting functions that are absolutely useful in javascript_javascript skills

Support Chinese PHP to split into array codes according to string length_PHP tutorial

Support Chinese PHP split into array code according to string length


The above is the detailed content of PHP method to split specified characters into arrays. 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