executing code from database

前端 未结 8 460
逝去的感伤
逝去的感伤 2021-01-29 14:42

I have a PHP code stored in the database, I need to execute it when retrieved.

But my code is a mix of HTML and PHP, mainly used in echo \"\";

A sample that look

8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-29 15:31

    See eval. It lets you pass a string containing PHP and run it as if you'd written it directly into your file.

    It's not a common practice to store executable PHP in a database; is the code you store really that different that it makes more sense to maintain many copies of it rather than adapting it to do the same thing to static data in the database? The use of eval is often considered bad practice as it can lead to problems with maintenance, if there's a way of avoiding it, it's normally worth it.

提交回复
热议问题