Template engine-problems with a PHP template

Source: Internet
Author: User
Tags php template
I wrote a template class to filter the contents of the. html file into a normal PHP tag, and then output it.

Currently read. html with the file_get_contents, and then regular filtering is normal, the final output to the page into a pure string, similar to

 
  Here is the HTML ...

How do I get it done?

PS: In the past I used the method of saving these output strings as a. php file, and then include this file. Now that the environment has changed, does not support directory IO, so I would like to directly execute it, is it feasible?

Reply content:

I wrote a template class to filter the contents of the. html file into a normal PHP tag, and then output it.

Currently read. html with the file_get_contents, and then regular filtering is normal, the final output to the page into a pure string, similar to

 
  Here is the HTML ...

How do I get it done?

PS: In the past I used the method of saving these output strings as a. php file, and then include this file. Now that the environment has changed, does not support directory IO, so I would like to directly execute it, is it feasible?

You can use it eval to execute a string, and the following my_template_parser is your own template function. However, eval the attention is inefficient and may have memory problems, so it is only recommended to test locally, formally or replace the PHP file with include the good.

Eval (My_template_parser (file_get_contents (' my-template.html ')));
  • 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.