Jump to content

simplexml and XML from a remote server


favedish

Recommended Posts

hi

first off, i must let you know that i'm an ASP proggie, and have very little PHP knowledge.

i have a requirement for some PHP to query a third party's remote database, which returns XML. i then need to parse and display the data.

i have got as far as taking the POSTed form data and producing a URL from it. i have proven this by means of using

  header("Location: ".$myurl);
 
  $myurl is of the form  http://domain.com/search.php?p=11&area=17&moreparams=lots

which gives me a page of XML as i would expect.

now i need to parse the XML....

i have tried simplexml_load_file($myurl) which throws an error of the form:

  parser error : Extra content at the end of the document
 
i've saved the XML into test.xml and put it on the server. then, simplexml_load_file('test.xml') works fine.

my guess is that i can't simplexml_lolad_file() from a remote server. is this the case? if so, is there an easy way around this?

or maybe the URL is just too long?

also, is it necessary for me to capture the POST data and reformat it into a URL? or can i change the <FORM> tag to a GET, call the remote DB search directly, and then somehow process the returned XML?

any help greatfully appreciated - but please keep it simple, cos as i said, i'm from the ASP world and all this is very new to me....

cheers
Link to comment
Share on other sites

sorry hitman6003, i tried what you suggested but got the same error.

here's the err msg in its entirety:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 2: parser error : Extra content at the end of the document in D:\wwwroot\a.php on line 38 PHP Warning: simplexml_load_string() [function.simplexml-load-string]: <b>Warning</b>: Invalid argument supplied for foreach() in <b>/appl/www/htdocs/ in D:\wwwroot\a.php on line 38 PHP Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in D:\wwwroot\a.php on line 38

i get the feeling that the remote server will accept the URL via a simple GET, but doesn't like it within a simplexml call. is that right?
Link to comment
Share on other sites

ok, so it's this:

Warning: Invalid argument supplied for foreach() in /appl/www/htdocs/extend/wn05/search_xmlliste_inc.php on line 69
25fffb44395ed97911d07ad4ecd87ef052970616_404731000
40473

but it works fine using header("Location:....") ....?

NB i have no access to the remote server other than this... it would be great if the peeps there were as helpful as the crew here ;)
Link to comment
Share on other sites

here's my little page:

[code]
<?php

//the form sends a variable set of variables, so i am dealing with it this way:

$s="";
foreach($_POST as $key => $value)

{
$s.= "&";
$s.= $key;
$s.= "=";
  $s.= $value;
}

$s="?".substr($s,1);

$myurl = "http://remote.com/page.php".$s;

echo file_get_contents($myurl);

//header("Location: ".$myurl);                  this works

//$parsed_doc = simplexml_load_string(file_get_contents($myurl));                  this doesn't

?>

[/code]

my foreach code at the top works fine.

it's a foreach loop on the remote that is throwing the error - and i don't have access to that code.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.