Home > Backend Development > PHP Tutorial > PHP explode() function usage and splitting string_PHP tutorial

PHP explode() function usage and splitting string_PHP tutorial

WBOY
Release: 2016-07-21 15:15:26
Original
1174 people have browsed it

Copy code The code is as follows:

// ### Split string####
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 is an array.

Syntax
explode(separator,string,limit)

参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。

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 negative, all but 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:
Copy code 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] => a
[4] => beautiful
[5] => day.
)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326098.htmlTechArticleCopy the code as follows: ? // ### Split string#### function jb51netcut($start ,$end,$file){ $content=explode($start,$file); $content=explode($end,$content[1]); return $content...
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template