PHP Explode examples and tutorials

Source: Internet
Author: User
Tags explode php explode split

PHP Explode examples and tutorials
Array explode (string separator, string string [, int limit])

Separator required. Specify where to split the string.
String required. The string to split.
Limit optional. Specify the maximum number of array elements to return.


Each element is a substring of string, which is separated by separator as a boundary point.

If the limit parameter is set, the returned array contains up to limit elements, and the last element will package

Contains the remainder of a string.

If separator is an empty string (""), Explode () returns FALSE. If the separator package

Contains a value that is not found in string, then explode () returns an array containing a single element of string.

In this case, we'll split the string into arrays:

<?php
$STR = "Hello World". It ' s a beautiful day. ";
Print_r (Explode ("", $str));
?>

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

<?php
Dividing a string into an array using the EXPLODE function
$source = "HELLO1,HELLO2,HELLO3,HELLO4,HELLO5";//separating strings by commas
$hello = Explode (', ', $source);

for ($index =0; $index <count ($hello); $index + +) {
echo $hello [$index];echo "</br>";
}

Example Three

<?php
$foo = ' uno dos tres '; Two spaces between "DOS" and "Tres"
Print_r (Explode (', $foo));
?>

Array
(
[0] => Uno
[1] => dos
[2] =>
[3] => Tres
)
Keep in mind that explode () can return, if separated immediately repeat two times (or more empty elements), as shown in the following

Example shows the following:

PHP Implode () function Instance Tutorial

Related Article

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.