预定义常量
下列常量由此扩展定义,且仅在此扩展编译入 PHP 或在运行时动态载入时可用。
常量 | 描述 | 自哪个版本起 |
---|---|---|
PREG_PATTERN_ORDER |
结果按照”规则”排序,仅用于 preg_match_all(), 即 $matches[0] 是完整规则的匹配结果, $matches[1] 是第一个子组匹配的结果,等等。 | since |
PREG_SET_ORDER |
结果按照”集合”排序,仅用于preg_match_all(), 即 $matches[0] 保存第一次匹配结果的所有结果(包含子组)信息, $matches[1] 保存第二次的结果信息,等等。 | |
PREG_OFFSET_CAPTURE |
查看 PREG_SPLIT_OFFSET_CAPTURE 的描述。
|
4.3.0 |
PREG_SPLIT_NO_EMPTY |
这个标记告诉 preg_split() 仅返回非空部分。 | |
PREG_SPLIT_DELIM_CAPTURE |
这个标记告诉 preg_split() 同时捕获括号表达式匹配到的内容。 | 4.0.5 |
PREG_SPLIT_OFFSET_CAPTURE |
如果设置了这个标记,每次出现的匹配子串的偏移量也会被返回。注意,这会改变返回数组中的值, 每个元素都是由匹配子串作为第 0 个元素,它相对目标字符串的偏移量作为第 1 个元素的数组。这个 标记只能用于 preg_split()。 | 4.3.0 |
PREG_UNMATCHED_AS_NULL |
This flag tells preg_match() and
preg_match_all() to include unmatched subpatterns in
$matches as null values. Without this flag, unmatched
subpatterns are reported as empty strings, as if they were empty matches.
Setting this flag allows to distinguish between these two cases.
|
7.2.0 |
PREG_NO_ERROR |
没有匹配错误时调用 preg_last_error() 返回。 | 5.2.0 |
PREG_INTERNAL_ERROR |
如果有 PCRE 内部错误时调用 preg_last_error() 返回。 | 5.2.0 |
PREG_BACKTRACK_LIMIT_ERROR |
如果调用回溯限制超出, 调用preg_last_error()时返回。 | 5.2.0 |
PREG_RECURSION_LIMIT_ERROR |
如果递归限制超出, 调用preg_last_error()时返回。 | 5.2.0 |
PREG_BAD_UTF8_ERROR |
如果最后一个错误时由于异常的utf-8数据(仅在运行在 UTF-8 模式正则表达式下可用)。 导致的,调用preg_last_error()返回。 | 5.2.0 |
PREG_BAD_UTF8_OFFSET_ERROR |
如果偏移量与合法的 UTF-8 代码不匹配(仅在运行在 UTF-8 模式 正则表达式下可用)。 调用 preg_last_error() 返回。 | 5.3.0 |
PREG_JIT_STACKLIMIT_ERROR |
当 PCRE 函数因 JIT 栈空间限制而失败,preg_last_error() 就会返回此常量。 | 7.0.0 |
PCRE_VERSION |
PCRE版本号和发布日期(比如: "7.0 18-Dec-2006 ")。
|
5.2.4 |

User Contributed Notes 2 notes
erutan409 at hotmail dot com ¶
6 years ago
PREG_PATTERN_ORDER: 1
PREG_SET_ORDER: 2
PREG_OFFSET_CAPTURE: 256
PREG_SPLIT_NO_EMPTY: 1
PREG_SPLIT_DELIM_CAPTURE: 2
PREG_SPLIT_OFFSET_CAPTURE: 4
PREG_NO_ERROR: 0
PREG_INTERNAL_ERROR: 1
PREG_BACKTRACK_LIMIT_ERROR: 2
PREG_RECURSION_LIMIT_ERROR: 3
PREG_BAD_UTF8_ERROR: 4
PREG_BAD_UTF8_OFFSET_ERROR: 5
PCRE_VERSION: %YOUR_VERSION_NUMBER%
Robert ¶
6 years ago
The new PREG_JIT_STACKLIMIT_ERROR constant introduced with PHP 7.0.0 has got a value of 6.
I experienced this error code when parsing a 112KB file. preg_match_all failed with this error. Interesting was: The matches array contained some entries, but not all as the command failed (I missed to check the return value).
Unfortunately you can not configure the stack-size of the PCRE JIT. The only way out was - at least for me - to disable the PCRE JIT via php.ini (pcre.jit=0).