PHP Tutorial: template engine based on regular expression replacement

Source: Internet
Author: User
I haven't encountered a PHP problem for a long time. This Regex problem takes a little time, and it is still the biggest backtracking and recursive restriction problem of the old problem. It is not difficult to modify the regular expressions with such problems after the learning is done. The main points are as follows. The template engine based on regular expression replacement is prone to the limit of maximum backtracking and recursion 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 don't pay attention to it or do not study it, you haven't encountered any PHP problems for a long time. This regular expression takes a little time, but it is still the biggest backtracking and recursive restriction problem of the old problem. It is not difficult to modify the regular expressions with such problems after the learning is done. The main points are as follows.

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

References

1. 2010, Laruence "deep understanding of the maximum backtracking/recursion restrictions of regular expressions (pcre)"

2. 2011, PHP Chinese manual preg_last_error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.