PHP partition function Preg_split () function, usage, example, parameter description

Source: Internet
Author: User

PHP partition function Preg_split () function, usage, example, parameter description

Preg_split

Definition and usage

The Preg_split () function splits a string with a regular expression.

Related functions: Spliti (), Str_split (), explode (), implode (), Chunk_split ()

Grammar

Preg_split (Pattern,subject,limit,flags)
Parameters Description
Pattern Regular expressions
Subject String to be split
Limit Limit the number of sub-strings to be split to only a limit
Flags Preg_split_no_empty
If this tag is set, Preg_split () will return to the non-empty part after the separation.
Preg_split_delim_capture
If this tag is set, the parentheses expression in the pattern used for the separation will be captured and returned.
Preg_split_offset_capture
If this tag is set, the string offset will be appended to each occurrence of the match returned. Note: This will change each element in the returned array so that each element becomes a delimited substring of the No. 0 element, and the 1th element is an array of the offset of the substring in subject.

Example

Preg_split () Gets the part of the search string

 
  

Output:

Array (    [0] = hypertext    [1] = Language    [2] = programming)

Separates a string into the character that makes up it

 
  

Output:

Array (    [0] = s    [1] = =    [2] = = R    [3] = i    [4] = n    [5] = g)

Separates a string and gets the offset of each part

 
  

Output:

Array ([    0] = = Array        (            [0] = = Hypertext            [1] = 0        )    [1] = = Array        (            [0] = = Language            [1] = [    2] = = Array        (            [0] = programming            [1] =        +))
  • 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.