The related content of orderly splitting of php strings is very important in php. This article will introduce the related operations of orderly splitting of php strings.
Here are these functions
chunk_split(): The function splits a string into a series of smaller parts.
explode(): Use one string to split another string
str_split(): Split the string into an array
chunk_split()
chunk_split(string,length,end)
Parameters Description
string Required. Specifies the string to be split.
length Optional. Numeric value that defines the length of the string block. The default is 76.
end Optional. A string value that defines what to place at the end of each string block. The default is \r\n.
<!--?php $str = "Shanghai"; echo chunk_split($str,1,"."); ?-->
Input result: S.h.a.n.g.h.a.i.
explode()
This function is the inverse function of implode(). It uses one string to split another string and returns an array.
array explode( string separator, string string [, int limit] )
<!--?php $str = 'one|two|three|four'; print_r(explode('|', $str)); print_r(explode('|', $str, 2)); // 负数的 limit(自 PHP 5.1 起) print_r(explode('|', $str, -1)); ?-->
The output results are as follows:
Array ( [0] => one [1] => two [2] => three [3] => four ) Array ( [0] => one [1] => two|three|four ) Array ( [0] => one [1] => two [2] => three ) str_split() str_split() 将字符串分割为一个数组,成功返回一个数组。 array str_split( string string [, int length] )
Parameters Description
string The string that needs to be divided
length is optional, indicating the length of each division unit, which cannot be less than 1
Example:
<!--?php $str = 'one two three'; $arr1 = str_split($str); $arr2 = str_split($str, 3); print_r($arr1); print_r($arr2); ?-->
The output result is as follows:
Array ( [0] => o [1] => n [2] => e [3] => [4] => t [5] => w [6] => o [7] => [8] => t [9] => h [10] => r [11] => e [12] => e ) Array ( [0] => one [1] => tw [2] => o t [3] => hre [4] => e )
This article explains the related operations of orderly splitting of PHP strings. For more related content, please pay attention to the PHP Chinese website.
Related recommendations:
How to use PHP to calculate the distance between two longitudes and latitudes
Explain PHP array traversal Related examples
#Explain the methods of PHP array classification and array creation
The above is the detailed content of Explain the related operations of orderly splitting of PHP strings. For more information, please follow other related articles on the PHP Chinese website!