开发者

What is a simple way to parse this specific xml using php?

开发者 https://www.devze.com 2023-03-19 11:18 出处:网络
Whay is a good way ( native way that w开发者_如何学运维orks in both php 4 and 5 ) to extract the value from this xml string

Whay is a good way ( native way that w开发者_如何学运维orks in both php 4 and 5 ) to extract the value from this xml string

<root>
<node1>
  <![CDATA[THE-TEXT]]>
</node1>
</root>

I wish to extract THE-TEXT content.


you can use simple xml with a third parameter to parse CDATA as Text:

look there: http://www.vijayjoshi.org/2009/09/22/quick-php-tip-how-to-parse-cdata-sections-using-simplexml/


Maybe something like this:

$dom = new DOMDocument();
$dom->loadXML($xml);
$descriptions = $dom->getElementsByTagName('node1');
foreach($descriptions as $desc)
{
   echo "<div>".$desc->textContent."</div>";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消