PHP split function usage and alternatives
The function of the PHP split function is to use regular expressions to split the string into different parts. However, the PHP split function is not recommended for versions after PHP 5.3.0, and it is recommended to use other functions such as preg_split , Explode and other functions to deal with, the following is the basic syntax and sample reference of PHP split function.
Basic syntax of PHP split function
split( $pattern , $string , $limit )
The first parameter of the function $pattern represents the character to be cut, split will split the second parameter string $string into many parts according to $pattern, and the third parameter $limit is the selected item, an integer, and is not filled in If you do, split will cut all $patterns in all strings. If you fill in $limit, the maximum number of cutting results is $limit, and the last split item is included to the end of the $string string.
PHP split function example
$NewString = "Welcome/to/Wibibi.";
$NewString = split ('[/.-]', $NewString);
echo $NewString[0].'<br>';
echo $NewString[1].'<br>';
echo $NewString[2];
?>
to
Wibibi
The alternative to the PHP split function
seems to be a useful split function. Why do you need an alternative? The main reason is that after PHP 5.3.0, the original POSIX Regex format is not recommended. Change to the PCRE specification. This may not be very clear, but if your PHP version is 5.3.0 or newer It is recommended to use the PHP preg_split function to replace the original split function. The preg_split function uses Perl compatible regular expressions, and its efficiency is much higher than that of simple split. But if you are not very familiar with regular expressions, and just want to cut the string, you can also consider the simple and efficient explode function. I believe that many problems can be solved, and the advantages of using the explode function are speed and use In addition to simplicity, it can also save the performance consumption of the regular PHP engine.
Post a Comment
0 Comments