Birden fazla yardım preg_match?

2 Cevap php
<?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);
?>

yakalama çoklu [test] ve [/ test] değer aaaaa ve bbbb nasıl?

2 Cevap

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

$array[1] istediğini sahiptir.

non regex yolu

$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";
    }
}

çıktı

$ php test.php
aaaaa
bbbb
cccc
ddd