Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simplexml_load_file does not load url

Status
Not open for further replies.

livestrong

Technical User
Nov 27, 2006
29
IE
Hi Everyone

for example

realdata.xml

and


contain the same xml

Code:
<?php
$realdata = simplexml_load_file('realdata.xml');
foreach ($realdata->ITEM as $item) { 
          printf("Quantity: %s\n", $item->QTY);
              }
?>

will work fine and return the data i need (the quantity)

however when i try to use a url

Code:
<?php
$realdata = simplexml_load_file('[URL unfurl="true"]http://www.myxmldata.asp?pid=111');[/URL]
foreach ($realdata->ITEM as $item) { 
          printf("Quantity: %s\n", $item->QTY);
              }
?>

no joy

I know this used to work in previous versions of php, but i'm using version 5 now.

Any idea's anyone??
 
I'm assuming that the pid=111 variable is used as a reference in the root file (I'm assuming index.asp) to a particular xml file.

If I'm wrong, then my first thought would be that you're not actually refering to an xml file.

It would help to know exactly what the url is refering to.


If it is a filename, then perhaps verify that the path is correct.

If it is in fact a string that the url refers to, then I would try to use simplexml_load_string option instead.

Have a variable store the string that the url refers to, then use simplexml_load_string($string);


I doubt this will help you any, as you surely know more about this than me, but sometimes it just takes a separate set of eyes to point out the obvious answer that has been staring you in the face for hours.
 
Hi again,

was just an example url

the real url is contained in the code below which is still giving me no joy.

Code:
<?php
$url = '[URL unfurl="true"]http://intouch.computer2000.com/xml/xmlonl.asp?custid=325009&prodid=1000193';[/URL]
$realdata = simplexml_load_string($url);
foreach ($realdata->ITEM as $item) { 
          printf("Quantity: %s\n", $item->QTY);
              }
?>

However as i said before when i copy this xml into a file
and run the below code it works.

Code:
<?php
$realdata = simplexml_load_file('realdata.xml');
foreach ($realdata->ITEM as $item) {
          printf("Quantity: %s\n", $item->QTY);
              }
?>
 
[1] There is no way simplexml_load_string() to work by feeding it with a url like that. Stick to your _load_file().
[2] If there is a problem, you should check the xmlonl.asp rather than anywhere else to begin with. Then make sure any permission issue on server-to-server communication.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top