The following is the php function written based on the explode() function to split the string. The main PHP intercepts the intermediate data according to the start and end, which is very Practical
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 the string into array.
Syntax
explode(separator,string,limit)
Description | |
---|---|
Required. Specifies where to split the string. | |
Required. The string to split. | |
Optional. Specifies the maximum number of array elements returned. |
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 the 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:
<?php $str = "Hello world. It's a beautiful day."; print_r (explode(" ",$str)); ?>
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] => a
[4] => beautiful
[5] => day.
)
The above is the detailed content of Usage instructions of php explode() function. For more information, please follow other related articles on the PHP Chinese website!