1 | <?php |
||
20 | abstract class Utils |
||
21 | { |
||
22 | /** |
||
23 | * Wrapper function for phps preg_split |
||
24 | * |
||
25 | * This function is inspired by {@link https://github.com/thecodingmachine/safe/blob/master/generated/pcre.php}. But |
||
26 | * since this library is all about performance we decided to strip everything we don't need. Reducing the amount |
||
27 | * of files that have to be loaded, ect. |
||
28 | * |
||
29 | * @param string $pattern The pattern to search for, as a string. |
||
30 | * @param string $subject The input string. |
||
31 | * @param int|null $limit If specified, then only substrings up to limit are returned with the |
||
32 | * rest of the string being placed in the last substring. A limit of -1 or 0 means "no limit". |
||
33 | * @param int $flags flags can be any combination of the following flags (combined with the | bitwise operator): |
||
34 | * *PREG_SPLIT_NO_EMPTY* |
||
35 | * If this flag is set, only non-empty pieces will be returned by preg_split(). |
||
36 | * *PREG_SPLIT_DELIM_CAPTURE* |
||
37 | * If this flag is set, parenthesized expression in the delimiter pattern will be captured |
||
38 | * and returned as well. |
||
39 | * *PREG_SPLIT_OFFSET_CAPTURE* |
||
40 | * If this flag is set, for every occurring match the appendant string offset will also be returned. |
||
41 | * Note that this changes the return value in an array where every element is an array consisting of the |
||
42 | * matched string at offset 0 and its string offset into subject at offset 1. |
||
43 | * |
||
44 | * @return string[] Returns an array containing substrings of subject split along boundaries matched by pattern |
||
45 | * |
||
46 | * @throws PcreException |
||
47 | */ |
||
48 | public static function pregSplit(string $pattern, string $subject, ?int $limit = -1, int $flags = 0) : array |
||
57 | } |
||
58 |