search

Home  >  Q&A  >  body text

php - string precompilation with tag template

Hello everyone, I encountered a problem when I was using php to do a project.
If you want to output a piece of html content with <?php ... ?>, usually write include or require file name at the end for output.
But I put this HTML content directly in the database. If I want to output it, can I only create a temporary file first, and then use the include temporary file name to output it? Is there any other way?

大家讲道理大家讲道理2753 days ago399

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 13:16:51

    You can directly Eval, but there are security risks

    eval(preg_replace('/^<]?php|\?>/', '', str))

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-16 13:16:51

    For example, the cache after template compilation mostly uses temporary files. If you want to store it in the database, you can also use the eval function. However, it is recommended to use cache files. The database must not be well designed.

    reply
    0
  • Cancelreply