The template engine based on regular expression replacement can easily meet the maximum backtracking/recursion restrictions of regular expressions.
The inertia matching is not terrible. Under normal circumstances, the template is not enough, and the limit is often not exceeded. The discuz template engine is used in large quantities. However, if you do not pay attention to or study, you may encounter errors and problems.
When preg _ * returns null, you must note that the function is is_null.
Errors are not terrible, but it is best to output all the errors so that debugging is easy.
In addition to the error cause, the matched text and the regular expression are also output, which makes debugging easy.
PHP code
Copy codeThe Code is as follows:
<? 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;
}
References
1. 2010, Laruence "deep understanding of the maximum backtracking/recursion restrictions of Regular Expressions (pcre)"
2. 2011, PHP Chinese manual preg_last_error