tags:

views:

142

answers:

1

I found http://www.ibm.com/developerworks/xml/library/x-xml2jsonphp/ , but I don't know how to use this code to get the xml from my web server. any ideas?

+2  A: 

The simplest way is with file_get_contents()

$xmlString = file_get_contents('http://www...../file.xml');

If you want a SimpleXML object you can use simplexml_load_file()

$xml = simplexml_load_file('http://www...../file.xml');

Both these methods require allow_url_fopen to be enabled. If it isn't, you can use curl - this is more complicated but also gives you more flexibility.

$c = curl_init('http://www...../file.xml');
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);

$xmlString = curl_exec($c);
$error = curl_error($c);
curl_close($c);

if ($error)
    die('Error: ' . $error);
Greg