Jump to content

Executing php code within a string?


littlened

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.