Jump to content

Find Php Code Between The <? And ?> Tags With Preg


oozo

Recommended Posts

Hi i have a database in wich I want to store php code. Using eval I can easily execute the php exept when I want to load a template in this file.

Expample:
a DB cell contains:
<? $array = array(1=>'bla', 2=>'bla2', 3=>'bla3');

foreach ($array as $v){
echo $v. "<br>";
} ?>

<form name="tesdt" action="eeee" method="post"> &nbsp;<input type="text" name="ttt" value="ttttt" /> </form> This is some <strong>sample text</strong>. You are using <a href="http://www.fckeditor.net/">FCKeditor</a>.

<? echo "hello" ?>


I would like to extract the php bits so I can eval these bits.

Can anybody help me? I am not very good in preg stuff.

Cheers and thanks!
Link to comment
Share on other sites

  • 5 months later...
[quote author=ToonMariner link=topic=97062.msg389181#msg389181 date=1151574878]
I can't see why you would need to do any pattern matching on this...

eval should work fine with breaking out of php.

also itr is recommended that you do not use the short hand tags - use <?php instead!!!


[/quote]

i have been looking into this subject a lot recently..

the code will be stored as a string, so if you were to eval that string you would get an error (try putting that all in a php file and running it :P)

im thinking you would need to do a preg_replace_callback, find the code with a reg expression eg - "/<?(.8)?>/siU" and then have a function to eval the code and return the result.

i understand this is an old topic, but if i could have found the solution to this problem when i was looking then i wouldnt have spent hours trying to figure it out. i hope this helps someone.
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.