开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜