Usage instructions of php explode() function

怪我咯
Release: 2023-03-12 22:06:02
Original
1814 people have browsed it

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]; 
} 
?>
Copy after login

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)); 
?>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!