开发者

Access XML file using PHP

I have a xml file which has an entry

<content type="html"></content>

Can I access it as echo $result->content;

If not let开发者_JAVA技巧 me know , coz the above does not seem to be working, there are pics, which I want to display.

Thanks Jean


$result = simplexml_load_file("/path/to/file.xml");

should do what you want.

EDIT: You've said that you have the content as HTML. If it's stored as HTML when it's passed to echo it's displayed as HTML content.

However, to get HTML into the XML document in the first place, it needs to be stored either as character entities or as a CDATA section.

If it's character entities, then all you need to do is call:

$result->content = html_entities_decode($result->content);

If you've stored it as CDATA, then you need to change the call to simplexml_load_file to the following:

$result = simplexml_load_file("/path/to/file.xml", "SimpleXMLElement", LIBXML_NO_CDATA);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜