littlened Posted January 12, 2007 Share Posted January 12, 2007 OK,what I've done is created a page which stores the content of a textbox in a mysql database.I then have another page which pulls the text from the database and displays it within a template. However is any php code is entered into the database is doesnt get parsed.I have a mixture of html, text, and 2 php includes stored in the database, and I'd like the contents of the string to be displayed and any php code executed.Is it possible to do this, I've read about exec() but I've not really tried it as I'm sure I've done it before and it didnt work.Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/ Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 [url=http://www.php.net/eval]eval[/url] should do the trick. [b]edit[/b]: php.net main site down at the mo by the looks of things, so try [url=http://uk.php.net/eval]here[/url]cheers Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159229 Share on other sites More sharing options...
littlened Posted January 12, 2007 Author Share Posted January 12, 2007 The problem I have is that the string contains a mixture of of html, text, and php. From what I've read eval requires that the string itself be php code, so any text and html I have in the string would need to be written as echo "blah blah blah";for example this may be what the string contains;<div class="content_left"><?php include('somefile.php'); ?></div>I need something that will treat the string like a normal php file, only parsing any php with it. Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159358 Share on other sites More sharing options...
GingerRobot Posted January 12, 2007 Share Posted January 12, 2007 I wonder if you could write the string contents to a file then include the file? Not sure if there is an easier way of doing it though... Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159360 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 take a look at the user comments at the bottom of the [url=http://www.php.net/eval]eval manual page[/url]. it seems that using a mixure of eval, regular expressions and callbacks, you can achieve pretty much what you're after.cheers Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159368 Share on other sites More sharing options...
littlened Posted January 12, 2007 Author Share Posted January 12, 2007 Absolutely spot on mate, got it sorted, thanks very much.[quote author=redbullmarky link=topic=122121.msg503398#msg503398 date=1168630390]take a look at the user comments at the bottom of the [url=http://www.php.net/eval]eval manual page[/url]. it seems that using a mixure of eval, regular expressions and callbacks, you can achieve pretty much what you're after.cheers[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159376 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 thanks to you to. if i hadn't gone looking further, i wouldnt have found [url=http://www.php.net/preg_replace_callback]preg_replace_callback[/url] which has just saved me a HELL of a lot of time and effort on something else ;)cheers Quote Link to comment https://forums.phpfreaks.com/topic/33914-executing-php-code-within-a-string/#findComment-159378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.