[英]preg_match multiple help?
<?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);
?>
如何从捕获[测试]和[/ test]中获得多个值aaaaa和bbbb?
preg_match_all("/\[test\](.*?)\[\/test\]/i", $string, $array);
$array[1]
有您想要的。
非正则表达式
$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";
}
}
产量
$ php test.php
aaaaa
bbbb
cccc
ddd
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.