Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.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
Php 创建矢量并获取所有图像?_Php_Preg Match - Fatal编程技术网

Php 创建矢量并获取所有图像?

Php 创建矢量并获取所有图像?,php,preg-match,Php,Preg Match,我需要一些帮助,获取我文章中的所有图像。 目前,为了仅获取第一张图像,我使用以下方法: $first_img = ''; $mycontent = $row['post_content']; $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches); $first_img = $matches [1] [0]; if(empty($first_img)){ //Def

我需要一些帮助,获取我文章中的所有图像。 目前,为了仅获取第一张图像,我使用以下方法:

$first_img = '';
$mycontent = $row['post_content'];
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $my1content, $matches); 
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/img/default.png";}
$first\u img='';
$mycontent=$row['post_content'];
$output=preg_match_all('//i',$my1content,$matches);
$first_img=$matches[1][0];
if(empty($first_img)){//定义默认图像
$first_img=“/img/default.png”;}
这将仅获取文章中的第一幅图像

所以我需要它,从文章中获取所有图像,并将它们显示在一行中


谢谢

函数将返回数组匹配,
foreach
循环就足够了

更好的模式:
/

要处理多个匹配项,可以执行以下操作:

$mycontent = '<img something="null" src="ggggg.gif"><br/><img src="bob.jpg">';
$output = preg_match_all('/<img(?:(?!src).)+src="?([^"\']+)/i', $mycontent, $matches, PREG_SET_ORDER); // find all src attributes
foreach($matches as $val) { //loop over <img> tags matches
    echo $val[1];
}
$mycontent='
'; $output=preg_match_all('/tags matches echo$val[1]; }
请您将代码粘贴到这里好吗?谢谢您更新了答案,改进了模式。
$mycontent = '<img something="null" src="ggggg.gif"><br/><img src="bob.jpg">';
$output = preg_match_all('/<img(?:(?!src).)+src="?([^"\']+)/i', $mycontent, $matches, PREG_SET_ORDER); // find all src attributes
foreach($matches as $val) { //loop over <img> tags matches
    echo $val[1];
}