0

I would like to learn how can I turn PHP String into a PHP script.

e.g.

$var = "echo 'Hello';";

and execute as

echo 'Hello';

If you need more detail or similar post exist please let me know.

2 Answers2

0

Just use eval function see this link https://www.w3schools.com/php/func_misc_eval.asp

Filip Račić
  • 90
  • 1
  • 7
0

You can do it by the PHP function eval. https://www.php.net/manual/en/function.eval.php

e.g:

$var = "echo 'Hello';";
eval($var);

// output:
// Hello

But take care it is an big security issue (it is not save and not good).

Richard
  • 618
  • 1
  • 9
  • 15