get all between <? ?> ignoring "<? ?>"
Posted: Fri May 19, 2006 3:51 am
I know im a nooby at regex but i so wanne learn this great thing.
How can i get all the contents between 2 <? ?> marks
i got this far
it echo's
whitch is wrong.
i just dont know how to tell the regex not to match if the ?> end sign is between ' ' or ""
How can i get all the contents between 2 <? ?> marks
i got this far
Code: Select all
<?php
$string = "<td valign='top' class='NavigationBackground'><?translate('body?>')?> <?run('Navigation','__default')?></td>";
// Reads the string and finds all php calls!
function extractTexts($contents){
preg_match_all("/<\?php(.*?)\?>|<\?(.*?)\?>/i",$contents,$matches);
// Merge <?php and <? matches
$matches = array_merge($matches[1],$matches[2]);
foreach ($matches as $key => $phpCode) {
echo $phpCode."\n";
}
}
extractTexts($string);
?>Code: Select all
translate('body
run('Navigation','__default')i just dont know how to tell the regex not to match if the ?> end sign is between ' ' or ""