0

I'm parsing XML with PHP using simplexml_load_file, then I json_encode and json_decode in order to get all the info as arrays:

$xml = simplexml_load_file('/var/www/darkglass/wp-content/themes/dark2/assets/xml/artists.xml');
$musicos = json_encode($xml);
$musicos = json_decode($musicos, true);

I'm having this problem where I want to add a HTML code inside the tag, but it only works if I add a character before the <![CDATA like the example below:

This doesn't work:

<band><![CDATA[<a class="abandlink" href="#">Cannibal Corpse</a>]]></band>

This works:

<band>.<![CDATA[<a class="abandlink" href="#">Cannibal Corpse</a>]]></band>

Any idea why is this happening?


You still have to cast the instance, however testing with instanceof first means the compiler won't raise an unchecked cast warning and also means you won't be surprised at runtime with an java.lang.ClassCastException if the object turns out to be something you didn't expect.

4

2 回答 2

1

您应该使用LIBXML_NOCDATA选项:

$xml = simplexml_load_file('artists.xml', 'SimpleXMLElement', LIBXML_NOCDATA);
于 2015-03-04T10:52:52.103 回答
-1

好吧,我找到了解决此问题的方法,我刚刚将substr,添加$band = substr($band, 1);到变量中,因此它删除了变量的第一个字符,并且可以正常工作。

于 2013-08-25T21:36:22.883 回答