The explode() function in PHP can split a string into an array according to a given separator, including the following steps: Determine the separator ($separator), which is the substring used for splitting in the string . Specify the string to split ($string). Use $array = explode($separator, $string); to split the string and store it in $array. The explode() function returns an array containing the split string fragments.
explode() function in PHP
explode()
function in PHP Used to split a string into an array based on the given delimiter. It accepts two parameters:
Usage:
<code class="php">$array = explode($separator, $string);</code>
Return result:
##explode() Function return An array containing split string fragments. If the delimiter is not in the string, the function returns an array containing the entire string.
Example:
<code class="php">$str = "PHP,JavaScript,HTML,CSS"; $array = explode(",", $str); print_r($array);</code>
Output:
<code>Array ( [0] => PHP [1] => JavaScript [2] => HTML [3] => CSS )</code>
Notes:
The above is the detailed content of How to use explode in php. For more information, please follow other related articles on the PHP Chinese website!