Как разобрать изображение вне узла, используя SimpleXML? - PullRequest
2 голосов
/ 29 октября 2010

У меня есть канал с изображениями в узле описания. Как я могу разобрать только URL изображения и только текст описания без разрыва строки между ними?

<description>&lt;img src='http://example.com/100915gignac-clement_g_70x70.jpg'&gt;&lt;/img&gt;&lt;br /&gt;(Source: Example.com) Québec annonce qu'une autorisation ministérielle sera nécessaire pour une prise de participation de plus de 30&amp;#160;% de la nouvelle société fusionnée Investissement Québec dans une entreprise.</description>

1 Ответ

1 голос
/ 29 октября 2010

Передайте содержимое узла расшифровки в другой SimpleXmlElement.

$sxe  = new SimpleXmlElement("<description>&lt;img src='http://example.com/100915gignac-clement_g_70x70.jpg'&gt;&lt;/img&gt;&lt;br /&gt;(Source: Example.com) Québec annonce qu'une autorisation ministérielle sera nécessaire pour une prise de participation de plus de 30&amp;#160;% de la nouvelle société fusionnée Investissement Québec dans une entreprise.</description>");
$img  = new SimpleXMLElement("<root>$sxe</root>");
$desc = (string) $img;
$src  = (string) $img->img['src'];

var_dump($desc, $src);

По какой-то причине SimpleXML, по-видимому, html_decodes-объектов самостоятельно

...