请告诉我123.jpg如何从这一行456.jpg的标签中推导出这些值:[img][/img]$str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]";
2 回答

小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
像这样的东西会起作用:
$re = '/\[img\](.*?\.jpg)\[\/img\]/m';
$str = 'Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $match) {
if (isset($match[1])) {
unlink($match[1]);
}
}

当年话下
TA贡献1890条经验 获得超9个赞
只是为了演示@Laim 报告的帖子中的方法:
<?php
$str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]";
preg_match_all('/\[img](.*?)\[\/img]/s', $str, $matches);
print_r($matches[1]);
?>
输出:
Array
(
[0] => 123.jpg
[1] => 456.jpg
)
- 2 回答
- 0 关注
- 99 浏览
添加回答
举报
0/150
提交
取消