The following is a php function written based on The explode () function to split and split strings. it is very useful for php to intercept intermediate data by start and end.
The code is as follows:
// #### Splitting strings ####
Function jb51netcut ($ start, $ end, $ file ){
$ Content = explode ($ start, $ file );
$ Content = explode ($ end, $ content [1]);
Return $ content [0];
}
?>
Explode definition and usage
The explode () function separates strings into arrays.
Syntax
Explode (separator, string, limit)
| Parameters |
Description |
| Separator |
Required. Specifies where to split the string. |
| String |
Required. The string to be split. |
| Limit |
Optional. Specifies the maximum number of returned array elements. |
Description
This function returns an array composed of strings. each element is a substring separated by a separator as a boundary point.
The separator parameter cannot be a null string. If separator is a null string (""), explode () returns FALSE. If the value of separator cannot be found in string, explode () returns an array containing a single element in string.
If the limit parameter is set, the returned array contains up to limit elements, and the last element contains the rest of the string.
If the limit parameter is negative, all elements except the last-limit element are returned. This feature is added in PHP 5.1.0.
Tips and comments
Note: The limit parameter is added to PHP 4.0.1.
Note: For historical reasons, although implode () can receive two parameter sequences, explode () cannot. You must ensure that the separator parameter is prior to the string parameter.
Example
In this example, we split the string into an array:
The code is as follows:
$ Str = "Hello world. It's a beautiful day .";
Print_r (explode ("", $ str ));
?>
Output:
Array
(
[0] => Hello
[1] => world.
[2] => It's
[3] =>
[4] => beautiful
[5] => day.
)