有一种删除图像的方法......
如何在$ description部分中使用src =“...”所示的图像并删除说明文字?
<?php
$html = "";
$url = "http://newsfeed.zeit.de/index";
$xml = simplexml_load_file($url);
for($i = 0; $i < 1; $i++){
$description = $xml->channel->item[$i]->description;
//removes image
$description = preg_replace("/<img[^>]+\>/i", "", $description);
$html .= "$description";
}
echo $html;
?>
答案 0 :(得分:0)
您首先稍微更改正则表达式以匹配图片,然后将其附加到$html
变量而不是$description
,如下所示:
$description = "Venenatis Adipiscing Aenean Mollis <img src='http://www.domain.com/images/cat.gif' /> Justo Egestas Nibh";
preg_match("/(<img[^>]+\>)/i", $description, $matches);
if (isset($matches[0])) {
$html .= $matches[0];
} else {
$html .= $description
}