Php separator string as array _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
The php separator string is an array. Explodeexplode uses one string to split another string arrayexplode (string $ separator, string $ string [, int $ limit]). This function returns an array composed of strings, each explode

Explode-use one string to separate another string
Array explode (string $ separator, string $ string [, int $ limit])

This function returns an array composed of strings. each element is a substring of a string, which is separated by a string separator as a boundary point. 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 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 string element.

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

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.

Note: When constructing an SQL statement, the query column can be written in this way.
Php code
$ Field = explode (':', '*'); // The usage of explode is unknown today.


Official demo:
Php code
// Example 1
$ Pizza = "piece1 piece2 piece3 piece4 piece5 piece6 ";
$ Pieces = explode ("", $ pizza );
Echo $ pieces [0]; // piece1
Echo $ pieces [1]; // piece2

// Example 2
$ Data = "foo: *: 1023: 1000:/home/foo:/bin/sh ";
List ($ user, $ pass, $ uid, $ gid, $ gecos, $ home, $ shell) = explode (":", $ data );
Echo $ user; // foo
Echo $ pass ;//*

?>

This article is from "pengjun1128"

Http://www.bkjia.com/PHPjc/478674.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478674.htmlTechArticleexplode explode splits another string array explode (string $ separator, string $ string [, int $ limit]) using one string. This function returns an array consisting of strings, each...

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.