Re: [PHP] Executing PHP code in a database
At 06:15 08.03.2003, Leo Spalteholz said: [snip] >I have a table that stores all the "boxes" that my website will >display on the sides. So far the content is simply stored in a text >field and then substituted for the box body. However this way I >can't have any php code in the boxes... What I thought I could do is >have another field that will contain any php code that I want for >that box and then execute that after I read it from the database. > >So I have two questions basically. >1. How would I go about executing php code in a string? >Say I have $code = "md5('blah');" how would I execute the code in >the string? To execute any code contained within a string you need to eval() it. Assuming you have this piece of code $uname = 'Leo'; $text = "Hello there, "; eval("?>$text2. If I instead include a file would it have access tio the local >variables? > >Ie. In a class I have this: >$strContent = "blah, this is the content I got from the database"; >include("includefilefromdatabase.php"); > >Is the $strContent variable then available from the include file? Yes. See http://www.vogelsinger.at/test.php for an example (will be available for 1-2 days). -- >O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Executing PHP code in a database
On March 7, 2003 09:15 pm, Leo Spalteholz wrote: > Hi, > I have a table that stores all the "boxes" that my website will > display on the sides. So far the content is simply stored in a > text field and then substituted for the box body. However this way > I can't have any php code in the boxes... What I thought I could > do is have another field that will contain any php code that I want > for that box and then execute that after I read it from the > database. > > So I have two questions basically. > 1. How would I go about executing php code in a string? > Say I have $code = "md5('blah');" how would I execute the code in > the string? > 2. If I instead include a file would it have access tio the local > variables? > > Ie. In a class I have this: > $strContent = "blah, this is the content I got from the database"; > include("includefilefromdatabase.php"); > > Is the $strContent variable then available from the include file? > > Thanks, > Leo Sorry about that. A simple search in the manual would have answered the first question But I'm still not sure about the second... Thx, Leo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Executing PHP code in a database
Hi, I have a table that stores all the "boxes" that my website will display on the sides. So far the content is simply stored in a text field and then substituted for the box body. However this way I can't have any php code in the boxes... What I thought I could do is have another field that will contain any php code that I want for that box and then execute that after I read it from the database. So I have two questions basically. 1. How would I go about executing php code in a string? Say I have $code = "md5('blah');" how would I execute the code in the string? 2. If I instead include a file would it have access tio the local variables? Ie. In a class I have this: $strContent = "blah, this is the content I got from the database"; include("includefilefromdatabase.php"); Is the $strContent variable then available from the include file? Thanks, Leo -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php