tags:

views:

77

answers:

3

I have an url return an XML page result. When I use this command:

print_r(file($url));

Its done, but when I use command:

$doc =  load($url);

after that I :

print_r($doc);

it out. Its print_r out nothing. I'm quite new in work with XML in PHP someone give advise, please! Thank you for your attention!

A: 

I am not really sure what you trying to do but for parsing an xml file in PHP there two main ways: DOM

$doc = new DOMDocument();
$doc->loadXML(file_get_contents($url));

SimpleXML

$xml = new SimpleXMLElement(file_get_contents($xmlstr));

file_get_contents Reads entire file into a string

RageZ
I'm using simplexml_load_file and get the same result like you suggest RageZ. But the result have many nested SimpleXMLElement Objectchildren. To deal with this I have to waste a lot of time and I'm in hurry now! :D
gacon
@gacon: you should use `xpath` to get only the data you need.
RageZ
A: 

@deceze and RageZ: I'm using load() to get its attribute like this

$url = 'web address return an XML result';
$xml = load($url);
$node1 = $xml->getElmentsByTagName('tagname');
$value = $node1->getAttribute('attribute1');

But I have an error $xml is not an object and I check out by print_r and I get nothing but with print_r(file($url)) its print out an array as I expect! @Franz: May be I get an error tag in XML file but I could not fixed this just work with the result!

gacon
Etiquette is to update your question if you have more info to add.
Mark
AFAIK `load()` is not a PHP function. So again, what does it do? Are you sure it does anything?
deceze
A: 

You could also unserialize the xml into a php array and use print_r(array). Take a look here: http://articles.sitepoint.com/article/xml-php-pear-xml%5Fserializer/3#

You will need a PEAR package for this

Martin Hoegh