Home >Backend Development >PHP Tutorial >Detailed explanation of the definition of explode() function in php
I believe that when you see the title, you will know that the explode() function in php is the string function. We also know the splitting function written by the explode() function. The php function of a string, then today we will give you a detailed introduction to the explode() function in PHP!
The following is a php function that splits and splits a string written based on the explode() function. The main php intercepts the intermediate data according to the start and end. It is very practical.
The code is as follows:
<? // ### 切分字符串 #### function jb51netcut($start,$end,$file){ $content=explode($start,$file); $content=explode($end,$content[1]); return $content[0]; } ?>
explode definition and usage
explode() function splits a string into an array.
Syntax
explode(separator,string,limit)
Parameters | Description |
---|---|
separator | Required. Specifies where to split the string. |
string | Required. The string to split. |
limit | Optional. Specifies the maximum number of array elements returned. |
Explanation
This function returns an array composed of strings, each element of which is a substring separated by separator as a boundary point .
separator parameter cannot be an empty string. If separator is the empty string (""), explode() returns FALSE. If separator contains a value that is not found in string, explode() returns an array containing a single element from string.
If the limit parameter is set, the returned array contains at most limit elements, and the last element will contain the remainder of the string.
If the limit parameter is a negative number, all elements except the last -limit elements are returned. This feature is new in PHP 5.1.0.
Tips and Notes
Note: The parameter limit was added in PHP 4.0.1.
Note: Due to historical reasons, although implode() can receive two parameter orders, explode() cannot. You must ensure that the separator parameter comes before the string parameter.
Example
In this example, we will split the string into an array:
The code is as follows:
<?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?>
Output:
Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )
Summary:
Through the study of this article, I believe that everyone knows the definition of the explode() function in php. I hope it will be useful to you. The work helps!
Related summary:
Detailed example of how php uses the explode() function to split a string into an array
php Instructions for using the explode() function and implode() function
explode() in php The difference between function and split() function
The above is the detailed content of Detailed explanation of the definition of explode() function in php. For more information, please follow other related articles on the PHP Chinese website!