获取值在标签[img][/img]php中
请告诉我如何得出这些值此行[img][/img]标记中的123.jpg和456.jpg:获取值在标签[img][/img]php中,php,Php,请告诉我如何得出这些值此行[img][/img]标记中的123.jpg和456.jpg: $str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]"; 类似这样的方法会奏效: $re = '/\[img\](.*?\.jpg)\[\/img\]/m'; $str = 'Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]'; preg_match_all($re, $str,
$str = "Text 1 [img]123.jpg[/img] Text 2 [img]456.jpg[/img]";
类似这样的方法会奏效:
$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]);
}
}
类似这样的方法会奏效:
$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
$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]);
?>
为了演示该帖子的方法,@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]);
?>
这回答了你的问题吗@唉,不,因为在我的问题中,是一个完全不同的结构。@GameEagle同样的方法仍然有效,你只需要一个不同的结构regex@GameEagle,事实上是的,因为你的结构是完全相同的-一些标签之间的文本,无论形状如何。这是否回答了你的问题@唉,不,因为在我的问题中,是一个完全不同的结构。@GameEagle同样的方法仍然有效,你只需要一个不同的结构regex@GameEagle,实际上是的,因为你的结构是完全相同的-一些标记之间的文本,无论形状如何。我如何为每个结果值使用函数?即取消链接。非常感谢!如何为每个结果值使用函数?即取消链接。非常感谢!