FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Extracting XML with PHP

 


moejoe
Hi!

Is there a way I can extract XML using PHP.

For Example:
Code:
<xml>
<value1>
<value2>something</value2>
</value1>
</xml>


What i need is everything between the <value1> tags. Is there a way i can do it?
Can I just use substr()?

Thanks.
Star Wars Fanatic
Google is your friend.
The top hit is this, take a look at the built in PHP functions for parsing XML:
http://us3.php.net/xml

Looks like xml-parse-into-struct() is the function your want, there are examples there so you can figure it out.
If you have any trouble with that, let us know and we can help you more.

P.S. You could use something like substr() but it looks like it would take quite a bit more then parsing it using the XML parser that is built into PHP.
rvec
or even better use simplexml
http://nl3.php.net/simplexml

It'll create an array from an xml file or string. This example is to get your xml as a string:
Code:
$string= <<<XML
<xml>
<value1>
<value2>something</value2>
</value1>
</xml>
XML;

$xml = simplexml_load_string($string);

echo 'To show something you echo '. $xml->value2;
moejoe
SimpleXML is a life saver

Thanks for the links Smile
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.