The preg_replace function separates strings by a regular expression.
array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] )
Separates the given string by a regular expression.
Parameter description:
$pattern: Pattern used for search, in string form.
$subject: input string.
$limit: Optional, if specified, the substring obtained by dividing the limit will only be limit, and the last substring returned will contain all remaining parts. The limit value is -1, 0 or null means "no limit". As a PHP standard, you can use null to skip setting flags.
$flags: optional, can be any combination of the following flags (bitwise OR operation | combination):
PREG_SPLIT_NO_EMPTY: If this flag is set, preg_split() will return the separated non-empty portion.
PREG_SPLIT_DELIM_CAPTURE: If this flag is set, bracket expressions used in delimited patterns will be captured and returned.
PREG_SPLIT_OFFSET_CAPTURE: If this flag is set, the string offset will be appended to the return for each occurrence of a match. Note: This will change each element in the returned array so that each element becomes an element starting from the 0th The elements are separated substrings, and the first element is an array consisting of the offset of the substring in the subject.
Returns an array of substrings separated by pattern boundaries.
The execution result is as follows:
Array( [0] => hypertext [1] => language [2] => programming)
The execution result is as follows:
Array( [0] => r [1] => u [2] => n [3] => o [4] => o [5] => b)
The execution result is as follows:
Array( [0] => Array ( [0] => hypertext [1] => 0 ) [1] => Array ( [0] => language [1] => 10 ) [2] => Array ( [ 0] => programming [1] => 19 ))