PHPexplode () function usage, splitting string

Source: Internet
Author: User
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.
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.