Forum Moderators: coopster

Message Too Old, No Replies

Help..Can I read in a XML file on the web with open?

         

kidofring

3:07 am on Nov 4, 2004 (gmt 0)



I want to read in a XML on the internet,
for example the address of XML is [test...]
I don't know what's the best way in reading XML with PHP,so I choose the open function to open that address,
it echo success, I think I can open it.
but nothing come out when I echo the $contents!
the return of echo "$fp" is
"successResource id #3 "
Have I already read it in my program?

Or there is some other functions better than open function in reading XML?

How can I read the XML on the web and phrase it?
Thanks a lot!

my code
////////////////////////////////
$open_url='http://test/test.xml';
$fp = fopen ($open_url, "r");
if($fp)
{
echo "success";
echo "$fp";
}
else {
echo "fail";
}

$contents = '';
while (!feof($fp)) {
$contents .= fread($fp, 8192);
}

echo "$contents";

Zipper

1:09 pm on Nov 4, 2004 (gmt 0)

10+ Year Member



Learn the fundamentals of parsing XML with PHP. this would be helpful..
[sitepoint.com...]

eaden

1:03 pm on Nov 6, 2004 (gmt 0)

10+ Year Member



in php5 you can do it in one line :

$xml = simplexml_load_file('http://example.com/new-zealand.xml');

That is using the new SimpleXML extension for PHP5.

mincklerstraat

1:27 pm on Nov 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you don't have php5, you can use PEAR's XML serializer (and unserializer) [pear.php.net]. If you can't swing installing this yourself or getting your host to do it, you can just include the file and the other PEAR classes it's dependent on and it'll work just fine.