- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = <<<'AHA'
abc
[code lang='javascript']
var a = 2.5;
[/code]
bcd
[code lang='php']
$this->foo();
[/code]
cde
[code lang='html']
<p clas = 'bar'><span>hello world</span></p>
[/code]
def
AHA;
$r='/((^|\[\/code\]).*?(\[code[^\]]*?\]|$))/s';
preg_match_all($r, $str, $a);
print_r($a[0]);