php / regex:单独的Feed数据

时间:2010-02-01 19:45:03

标签: php regex

<description>&lt;img src='http://example.com/Pic_018_70x70.gif'&gt;&lt;/img&gt;&lt;br /&gt;This is the content of the description.</description>

如果我在图片的描述字段中有图片,我该如何将图片分成变量并去除噪点并删除描述呢?

2 个答案:

答案 0 :(得分:0)

这将为您提供问题中字符串的img src属性的值,并为您提供文本:

$sxml = new SimpleXMLElement(html_entity_decode($str));
$images = $sxml->xpath('//@src');
$text = $sxml->xpath('//description');

echo $images[0];  // http://example.com/Pic_018_70x70.gif
echo $text[0];    // This is the content of the description.

答案 1 :(得分:0)

您也可以使用simplexml

$xml = simplexml_load_string($string);
$description = $xml->description;