问题
I'm not that good at Regex,
Can you give me a pattern to match any php tags? [<?
, <?php
]
if you have a nice and simple guide for Regex i'd be happy to have it too :)
I already tried:
'/^(<\?)$/'
But it doesn't really help =/
Thanks!
回答1:
You will need preg_match_all to match tags, plural. The below will match blocks of PHP and store the code.
preg_match_all( '/<\?php(.+?)\?>/is', $php, $blocks );
print_r( $blocks );
One issue will be if you happen to have the string '?>' in your code not occuring as a PHP closing tag. Would need to know more about your file(s) to advise.
来源:https://stackoverflow.com/questions/20315444/how-to-match-php-tags-with-regex