wickedneat — 2013-03-25T14:16:48-04:00 — #1
I have a table in a database that has content and a php code.
Hello my name is <?php echo $var; ?>.
Whenever I echo the content from the table it does not execute the PHP code. It just displays the code.
Any advice on how I can get the PHP to execute.
kylewolfe — 2013-03-25T15:16:09-04:00 — #2
To run a string as php code, use eval();
But why on earth would you be doing this?
wickedneat — 2013-03-25T15:33:49-04:00 — #3
I have previously tried using eval but I get the following error:
Parse error: syntax error, unexpected '<' in hello.php(58) : eval()'d code on line 1
kylewolfe — 2013-03-25T15:47:13-04:00 — #4
It will execute the entire string... "Hello my name is" is not valid php. You'd have to find Php tags, pull them out of the string and execute only that (after removing the php tags)
biglittle — 2013-03-26T00:17:35-04:00 — #5
$var = 'omg';
$variable = 'Hello my name is <?php echo $var; ?>.';
preg_match_all('/<?php (.*?) \\?>/ms', $variable, $match);
Curious, what's your use?
codersempire — 2013-03-26T02:42:50-04:00 — #6
Are you trying to print the content from db.If yes,then this code can help you:
mysql_connect("hostname", "username", "password") && mysql_select_db("dbname") or die;
$details = mysql_query("select * from tablename");
while ($detail = mysql_fetch_assoc($details))
$name = $detail['name'];