Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 oozo

oozo
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 28 June 2006 - 02:52 PM

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...>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!

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 29 June 2006 - 09:54 AM

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!!!


follow me on twitter @PHPsycho

#3 Nooty

Nooty
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 17 December 2006 - 12:19 AM

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!!!



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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users