Is it possible to put a PHP code in a string. see the strings functions here: http://php.net/manual/en/function.eval.php I want to make a string called "$name" which should have the value as the following: $db = new mysql("localhost", "user", "Pass", "DB"); $query = $db->query("SELECT * FROM strings'") or die($db->error()); $page_HTML = mysql_fetch_array($query);eval($page_HTML['name']); PHP: Would that be possible somehow? EDIT: I tried the following: $name = ' $db = new mysql("localhost", "user", "Pass", "DB"); $query = $db->query("SELECT * FROM strings'") or die($db->error()); $page_HTML = mysql_fetch_array($query);eval($page_HTML['name']); '; PHP:
Confused ? function do_this(){ $db = new mysql("localhost", "user", "Pass", "DB"); $query = $db->query("SELECT * FROM strings'") or die($db->error()); $page_HTML = mysql_fetch_array($query);eval($page_HTML['name']); } //execute the function do_this(); PHP: do_this() is a function, a command to execute what's between { here & here } so if you look at it this way, do_this is effectively a variable that holds a string of commands. Other then that could you explain a little more about the purpose of your request, I'm sure someone will reply. EDIT: I'm confusing myself now, but using your reference to eval, something like this should work: <?php function do_this(){ $db = new mysql("localhost", "user", "Pass", "DB"); $query = $db->query("SELECT * FROM strings'") or die($db->error()); $page_HTML = mysql_fetch_array($query);eval($page_HTML['name']); } ?> <html> <head> <!-- ... --> </head> <body> <!-- ... --> <?php eval("?>" . do_this() . "<?"); ?> <!-- ... --> </body> </html> PHP: