Home > Article > Backend Development > How to use php explode function
PHP explode function is used to use one string to split another string. Its syntax is explode(separator, string, limit). The parameter separator is required, which refers to where to split the string; string is required, which refers to the characters to be split. string.
How to use php explode function?
php explode() function syntax
Function: string Scattered into an array
Syntax:
explode(separator,string,limit)
Parameters:
separator Required. Specifies where to split the string.
string Required. The string to split.
limit Optional. Specifies the number of array elements to be returned. Possible values: greater than 0 - returns an array containing at most limit elements, less than 0 - returns an array containing all but the last -limit elements, 0 - returns an array containing one element
Instructions:
Break up the string into an array. The "separator" parameter cannot be an empty string. This function is binary safe.
php explode() function usage example 1:
<?php $str = "Hello world. I'm study in php.cn!"; print_r (explode(".",$str)); ?>
Output:
Array ( [0] => Hello world [1] => I'm study in php [2] => cn! )
php explode() function usage example 2:
<?php $arr = "Learning PHP is a good choice"; print_r(explode(" ", $arr)); ?>
Output:
Array ( [0] => Learning [1] => PHP [2] => is [3] => a [4] => good [5] => choice )
This article is an introduction to the PHP explode function. I hope it will be helpful to friends in need!
The above is the detailed content of How to use php explode function. For more information, please follow other related articles on the PHP Chinese website!