Home > Backend Development > PHP Tutorial > PHP explode function

PHP explode function

WBOY
Release: 2016-08-08 09:21:16
Original
1536 people have browsed it

Definition and usage

explode() function splits a string into an array.

Syntax

explode(separator,string,limit)
Parameters Description
separator Required. Specifies where to split the string.
string Required. The string to split.
limit optional. Specifies the maximum number of array elements returned.

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() will return FALSE. If separator contains a value not found in string , then explode() will return 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 will contain the remainder of the string.

If the limit parameter is negative, all elements except the last -limit elements are returned. This feature is new in PHP 5.1.0.

Tips and Notes

Note: The limit parameter 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:

explode(" ",$str)); ?>

Output:

Array ( [0] => Hello [1] => world. [2] => It's [3] => a [4] => beautiful [5] => day. )

Copyright statement: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

The above introduces the PHP explode function, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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