PHP SimpleXMLElement - 无法从 Feed 中检索 'Description' 元素

PHP SimpleXMLElement - Can't Retrieve 'Description' Element From Feed

我不太了解如何抓取 XML 文档。可能有点误会。

供稿 URL:http://www.simplifyingthemarket.com/feed/

代码:-

$url = 'http://www.simplifyingthemarket.com/feed/';
$XmlObject = new SimpleXmlElement( file_get_contents($url) );
print_r($XmlObject->channel[0]->item[0]->description[0]);

输出:-

SimpleXMLElement Object ( )

要求的输出:-

<a href="http://www.simplifyingthemarket.com/wp-content/uploads/2015/04/Where-Should-I-Retire.jpg"><img class="alignnone wp-image-30608" src="http://www.simplifyingthemarket.com/wp-content/uploads/2015/04/Where-Should-I-Retire.jpg" alt="Where Should I Retire [INFOGRAPHIC] &#124; Simplifying The Market" width="600" height="1035" /></a>
 <h4>Some Highlights From The Report:</h4>
 <ul>
 <li>80% of all pre-retirees in the South Atlantic region plan to stay there in retirement</li>
 <li>4 out of 10 pre-retirees plan to relocate in retirement</li>
 <li>Retirees in the South Central Region are most satisfied with their Cost of Living</li>
 <li>For more information or to read the full report: <a href="https://www.ml.com/articles/age-wave-survey.html">Click Here</a></li>
 </ul>

注意:我的客户已经购买了他们的饲料,所以不存在法律问题。联系方式可提供更多信息。

为了以字符串形式访问节点的值,您首先必须将其转换为字符串。在你的情况下它会是这样的:

print_r((string) $XmlObject->channel[0]->item[0]->description[0]);

致谢:The SimpleXMLElement class