Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取值​在标签[img][/img]php中_Php - Fatal编程技术网

获取值​在标签[img][/img]php中

获取值​在标签[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,

请告诉我如何得出这些值​​此行[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, $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,实际上是的,因为你的结构是完全相同的-一些标记之间的文本,无论形状如何。我如何为每个结果值使用函数?即取消链接。非常感谢!如何为每个结果值使用函数?即取消链接。非常感谢!