Page 1 of 1

echo php from db

Posted: Sun Oct 10, 2004 5:04 am
by Benneth
Hi Guys,

I have searched the forums but have not found anything related to what i want to do.

Basically the subject says it all. I want to echo ( or 'use' ) php from a database.

I currently have it working fine for html, but when i chuck in some php it seems to fall over.

Ok an example...

Code: Select all

while ( $row = mysql_fetch_array($result) ) {
       	echo $row['strContent'];
}
So if i chuck some html in strContent in the db it would echo it fine, in html.

example

Code: Select all

<h1>This is heading 1</h1> // so here, it would decode the html and display "This is heading 1"
Now, if i chuck in some PHP in strContent nothing appears to happen.

example, if strContent contained

Code: Select all

<? echo "Hi - this just will not display!"; ?>
I used code tags because it's stored as plain text so not really php... but i want it to be displayed as php on my page.

Now i may have missed something really simple here, perhaps a php setting for echo to properly decode and display php with echo ? is there another command to use? I tried print and return... no luck here.

Any help would be much appreciated! Thanks guys

Posted: Sun Oct 10, 2004 5:24 am
by vigge89
check out the [php_man]eval[/php_man]() function, it lets you execute a string as php code

Posted: Sun Oct 10, 2004 6:07 am
by twigletmac
But the best thing is to avoid having to use eval() by not storing PHP in a database.

Mac

Posted: Sun Oct 10, 2004 6:27 am
by mudkicker
and it's very unsafe. instead of this idea you can include()...

Posted: Sun Oct 10, 2004 9:59 am
by feyd
I'd suggest properly usage of templates, with the content itself being stored in the database or in local files would be the "best practice" solution to your set up.

If you must have code in the database, I seriously hope you have spectacular security.