preg_match multiple help?
<?PHP
$st开发者_JAVA技巧ring = "[test]aaaaa[/[test][test]bbbb[/test][test]cccc[/test][test]ddd[/test]";
echo $string . "<br>";
preg_match("/\[test\].*?(\[\/test\])/i", $string, $m);
print_r($m);
?>
how to get value aaaaa and bbbb in multiple from capture [test] and [/test] ?
preg_match_all("/\[test\](.*?)\[\/test\]/i", $string, $array);
$array[1]
has what you want.
non regex way
$string = "[test]aaaaa[/test][test]bbbb[/test][test]cccc[/test][test]ddd[/test]";
$s = explode('[/test]',$string);
foreach ($s as $v){
if( strpos( $v,"[test]" )!==FALSE ){
$t=explode("[test]",$v);
print $t[1]."\n";
}
}
output
$ php test.php
aaaaa
bbbb
cccc
ddd
精彩评论