获取标签 [img][/img] php 中的值

请告诉我123.jpg如何从这一行456.jpg的标签中推导出这些值:[img][/img]

$str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]";


狐的传说
浏览 100回答 2
2回答

小怪兽爱吃肉

像这样的东西会起作用:$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]);    }}

当年话下

只是为了演示@Laim 报告的帖子中的方法:<?php&nbsp; &nbsp; $str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]";&nbsp; &nbsp; preg_match_all('/\[img](.*?)\[\/img]/s', $str, $matches);&nbsp; &nbsp; print_r($matches[1]);?>输出:Array(&nbsp; &nbsp; [0] => 123.jpg&nbsp; &nbsp; [1] => 456.jpg)
打开App,查看更多内容
随时随地看视频慕课网APP