Regular expression: PHP split and php function explode

Source: Internet
Author: User
: This article mainly introduces the regular expression of PHP split and the php function explode. if you are interested in the PHP Tutorial, refer to it.
  • Preg_split ($ pattern, $ subject)
    Use $ pattern to match the string, use the matched string as the split point, split the subject into multiple strings, and put them into an array.
  • Explode (string $ delimiter, string $ string [, int $ limit])

    The function returns an array composed of strings. each element is a substring of a string, which is separated by a string delimiter as a boundary point.

    If the limit parameter is set and it is a positive number, 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.

    If the limit value is 0, it is regarded as 1.
    This function returns an array composed of strings. each element is a substring of a string, which is separated by a string delimiter as a boundary point.

    If delimiter is a null string (""), explode () returns FALSE. If delimiter contains a value that cannot be found in string and uses a negative limit value, an empty array is returned. Otherwise, an array containing a single string element is returned.

// Example 1 $ pizza = "piece1 piece2 piece32 piece42 piece5 piece6"; $ pieces = explode ("2", $ pizza,-1); echo'
  '; Echo $ pieces [0]; // piece1echo $ pieces [1]; // piece2echo'
  '; Show ($ pieces); echo'
  '; // Example 2 $ data = "foo: *: 1023: 1000:/home/foo:/bin/sh"; list ($ user, $ pass, $ uid, $ gid, $ gecos, $ home, $ shell) = explode (":", $ data); echo $ user; // fooecho $ pass; // * echo'
  ';

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above section describes the regular expression in PHP, the split and the php function explode, including some content, hope to be helpful to friends who are interested in the PHP Tutorial.

    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.