I solve this problem in writing my own framework and cms: small fragments of html code are loaded from the database, as well as php scripts.

In the database, the record looks like this:

<div style="font-size: 18px;"><? echo "тест";?></div> 

When outputting, I write the connection to the database and data output:

 $where = 'id = 1'; $Current_page = $BDConnect->select('pages', Array('*'), $where); foreach ($Current_page as $html) echo $html['text_page']; 

As a result, the page writes text with the text:

 <div><? echo "тест";</div> 

How to make it not a text, but a part of html-code?

    1 answer 1

    You need echo replaced by eval() . And, since you have this HTML code, frame it with tags.

     foreach ($Current_page as $html) eval('?> ' . $html['text_page']); 

    but remember that the eval() function is very dangerous because of the ability to execute any code

    From the documentation

    Caution Using eval () can be very dangerous because it allows you to execute arbitrary code. Using this feature is not recommended. If you are completely convinced that there is no other way to reproduce the necessary functionality, pay special attention to the exceptions to the processing of data entered by the user in this way, without special processing and validation.

    • In what sense is dangerous? Is code substitution possible when generating code? - IntegralAL
    • @IntegralAL Are you sure that you will not have any malicious code in the database? - Anton Shchyrov
    • one
      for eval in any code, and not only php you need to give a hand - tcpack4
    • one
      @ tcpack4 This is unconstructive. If you have a better answer, add it. - svgrafov
    • @ tcpack4 I completely agree. But I don’t see any other solutions to the problem - Anton Shchyrov