Home > Article > Backend Development > PHP method to split specified characters into arrays
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!