Page 1 of 1

get strings from XML using php

Posted: Tue Nov 20, 2007 2:30 am
by Sindarin
I am trying to figure out how xml and php work together. It seems more complicated than fread().
I have several xml files in a folder which have the data I want to display on a page,
how can I read the sections and display them on the page using php?

Let's say the .xml file is:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<post>
<title><b>Welcome</b></title>
<description>welcome to my site.</description>
</post>
<post>
<title><b>2nd post</b></title>
<description>this is another post. <a href="http://www.google.com"> http://www.google.com </a></description>
</post>
<?xml>
So when read, it would display:

Welcome

welcome to my site.

2nd post

this is another post. http://www.google.com

Posted: Tue Nov 20, 2007 9:14 am
by Christopher

Posted: Fri Nov 23, 2007 6:04 am
by Sindarin
So should I go with php 4 xml? Or it will become deprecated and replaced by simplexml?


Also the problem I have is that those examples are not easy.

I have found this one here: http://www.kirupa.com/web/xml_php_parse_beginner.htm
but I can't get html to work between each of the xml contents...

Posted: Fri Nov 23, 2007 10:56 am
by superdezign
Try using the PHP DOM which follows the same standards as the W3C DOM. If you've ever used the DOM before (i.e. in JavaScript), it'll be very easy to work with.