請告訴我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 關注
- 121 瀏覽
添加回答
舉報
0/150
提交
取消