php 正则表达式取[img][⼀img]标签里面的东西

2024-12-29 12:01:18
推荐回答(3个)
回答1:

 
$string = '[img]http://www.baidu.com/img/bdlogo.gif[/img]百度百度[img]http://127.0.0.1/jx09/p_w_upload/Mon_1308/196_403966_392c1785279171a.png[/img]

sssss

';
preg_match_all("|\[img\](.*)\[/img\]|iUs",$string,$arr);
foreach($arr[0] as $v){
     echo $v.'
';
}


回答2:

$str = '[img]http://www.baidu.com/img/bdlogo.gif[/img]百度百度[img]http://127.0.0.1/jx09/p_w_upload/Mon_1308/196_403966_392c1785279171a.png[/img]

sssss

';

preg_match_all("|\[img\](.*)\[/img\]|isU",$str,$myarr);


print"
";
print_r($myarr[0]);
print"
";

回答3:

$content = '[img]http://www.baidu.com/img/bdlogo.gif[/img]百度百度[img]http://127.0.0.1/jx09/p_w_upload/Mon_1308/196_403966_392c1785279171a.png[/img]

sssss

通过正则后我想得到这个结果[img]http://www.baidu.com/img/bdlogo.gif[/img]
[img]http://127.0.0.1/jx09/p_w_upload/Mon_1308/196_403966_392c1785279171a.png[/img]';

preg_match_all("/\[img\](.*)\[\/img\]/iUs", $content, $arr);

foreach($arr[1] as $v){
echo $v.'
';
}

?>
preg_match_all("/\[img\](.*)\[\/img\]/iUs", $content, $arr); 匹配所有