A small problem
| From: | Alejandro | Date: | Tue, 11 Mar 2003 12:29:18 +0000 |
| Subject: | A small problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-139122@lists.php.net to get a copy of this message | ||
Hi all in the PHP list. I'm trying to deal with Regular Expressions, but somehow it is getting
more difficult. I´m trying to do the folowing:
Read a text and get all of the PHP code out of it, highlight it and then print all in nice HTML.
I'm using this to get the PHP code:
ereg("<\?.*\?>",$Text,$PHP_code);
It works, yeah, but on a situation like this:
<?
echo "aaaa";
?>
This is some other no php code
<?
echo "this is PHP";
?>
It returns everything. What i really need is to get the contents between <? and ?>, and only
that. I can imagine the RegExp is diung it right, because ideed there are <? and, at the end of
the text, another ?>, but it is not clever enough to take the PHP UP TO THE FIRST COINDICENCE OF
?>, and so on, and so on...
Can anyone help me? I would appreciate it very much.
Thanks anyway