tags:

views:

79

answers:

2
<?PHP
    $string = "[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] ?

+2  A: 
preg_match_all("/\[test\](.*?)\[\/test\]/i", $string, $array);

$array[1] has what you want.

Matthew Flaschen
+1  A: 

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
ghostdog74