Code: Select all
$matches = array();
preg_match_all('#<\?php(.+)#', $source, $matches, PREG_SET_ORDER);
I would like it to be as robust as possible, taking into account the "last" closing PHP block is not required and that the starting PHP block can be either <? or <?php (<% is not required).
How do I make the <? required and the trailing 'php' optional without grouping the 'php' in a [] or ()
Also, do I need to use $ to tell the regex to continue until the end of the source file or is this already greedy?
p.s-Extracting <script type="php"> is not required either -- this isn't for security but source code metrics
Cheers,
Alex