It's been a long time since I've had a problem with PHP, and this is a bit of an issue, and it's the biggest retrospective and recursive limitation of old problems. After learning it is not difficult to modify debugging has such a problem. Mainly the following points.
A template engine that is based on regular expression substitution can easily meet the maximum backtracking/recursion restrictions for regular expressions.
Lazy matching is not scary, normally the template is not enough, often do not exceed the limit, Discuz template engine is used heavily. But instead of paying attention and not learning, it is easy to write mistakes and encounter problems.
When preg_* returns NULL, it should be noted that the judgment function is is_null.
Error is not scary, but it is best to complete the error output, so debugging is very easy.
In addition to the output error reason, but also to output matching text and the use of regular, so it is easy to debug.
PHP code
- <?php
- if (is_null($tmp)) {
- $error _code = Preg_last_error ();
- Switch($error _code) {
- case preg_no_error:
- echo ' preg_no_error ';
- break;
- case preg_internal_error:
- echo ' preg_internal_error ';
- break;
- case preg_backtrack_limit_error:
- echo ' preg_backtrack_limit_error ';
- break;
- case preg_recursion_limit_error:
- echo ' preg_recursion_limit_error ';
- break;
- case preg_bad_utf8_error:
- echo ' preg_bad_utf8_error ';
- break;
- case preg_bad_utf8_offset_error:
- echo ' preg_bad_utf8_offset_error ';
- break;
- default:
- echo ' unknow ERROR ';
- }
- exit;
- }
|
Resources
1, laruence "deep Note regular (PCRE) maximum backtracking/recursion limit"
2, PHP, Chinese manual preg_last_error
(Source: Breeze Lab )