Home >Backend Development >PHP Tutorial >Usage instructions of php explode() function

Usage instructions of php explode() function

怪我咯
怪我咯Original
2017-07-06 11:21:281834browse

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)

##ParametersDescriptionseparatorRequired. Specifies where to split the string. stringRequired. The string to split. limitOptional. Specifies the maximum number of array elements returned.
Description

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:

The code is as follows:

<?php 
$str = "Hello world. It&#39;s a beautiful day."; 
print_r (explode(" ",$str)); 
?>

Output:


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn