在我目前的网站上,我正在使用这个代码来获取第一张图片,witch在帖子里面
$first_img = '';
$my1content = AD($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";
}我想知道如何获取帖子中的所有图片,而不仅仅是第一张。感谢您阅读这封邮件。
发布于 2011-09-03 06:04:24
$matches1应该是一个数组,遍历$matches1以获得所有的img标签。这里假设$my1content拥有所有的内容。
for ($matches[1] as $match) {
//do the stuff you want to do with a match
$imgUrl = $match[1]; //Do something with this
}https://stackoverflow.com/questions/7289616
复制相似问题