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] = +))