Reputation: 75
i tried to some the ways load data xml from URL before ask this question but all same failed . Same have some special characters in XML url . this is error
Warning: simplexml_load_file(): I/O warning : failed to load external entity " " in D://....;
And this is my code :
$url = 'http://website.com?xml¶m1=1¶m2=2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url); // get the url contents
$data = curl_exec($ch); // execute curl request
curl_close($ch);
$xml = simplexml_load_string($data);
$json = json_encode($xml);
echo $json;
Thanks every helping
Upvotes: 1
Views: 7067
Reputation: 57121
You could load the URL more simply using
$context = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));
$url = 'http://website.com?xml¶m1=1¶m2=2';
$xml = file_get_contents($url, false, $context);
$xml = simplexml_load_string($xml);
print_r($xml);
Edit: There is some talk about error 403 in various places, one suggestions is to set the user agent prior to this call:
ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0)');
(Taken from file_get_contents() give me 403 Forbidden)
Upvotes: 1