favedish Posted December 13, 2006 Share Posted December 13, 2006 hifirst 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=lotswhich 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 https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/ Share on other sites More sharing options...
hitman6003 Posted December 13, 2006 Share Posted December 13, 2006 What are you trying to accomplish with the xml?You can use simplexml_load_string rather than load_file....[code]$parsed_doc = simplexml_load_string(file_get_contents($myurl));[/code] Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140736 Share on other sites More sharing options...
favedish Posted December 14, 2006 Author Share Posted December 14, 2006 it's basic data from a real estate site, that has to be displayed in a web page. nothing in any way tricky ;Dthanks fot the suggestion, i'll give it a go. Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140747 Share on other sites More sharing options...
drifter Posted December 14, 2006 Share Posted December 14, 2006 what is the name of the system you are trying to get data from - I may have some good code to help you out a bit. Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140750 Share on other sites More sharing options...
favedish Posted December 14, 2006 Author Share Posted December 14, 2006 it's a real estate system based in austria - http://www.wohnnet.at/ Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140752 Share on other sites More sharing options...
favedish Posted December 14, 2006 Author Share Posted December 14, 2006 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 https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140755 Share on other sites More sharing options...
drifter Posted December 14, 2006 Share Posted December 14, 2006 the remote server does not even know you have simplexml - file get contents is just a get call - then after that is return then it is passed to the simplexmldo file get contents - then echo the result and look at it. what do you see? Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140756 Share on other sites More sharing options...
favedish Posted December 14, 2006 Author Share Posted December 14, 2006 ok, so it's this:Warning: Invalid argument supplied for foreach() in /appl/www/htdocs/extend/wn05/search_xmlliste_inc.php on line 6925fffb44395ed97911d07ad4ecd87ef052970616_40473100040473but 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 https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140760 Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 what code are you using that has a foreach loop? Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-140771 Share on other sites More sharing options...
favedish Posted December 14, 2006 Author Share Posted December 14, 2006 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 https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-141029 Share on other sites More sharing options...
hitman6003 Posted December 14, 2006 Share Posted December 14, 2006 Use urlencode on your $value variables:[code]foreach($_POST as $key => $value) { $s.= "&"; $s.= $key; $s.= "="; $s.= urlencode($value); }[/code] Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-141180 Share on other sites More sharing options...
favedish Posted December 16, 2006 Author Share Posted December 16, 2006 still the same error.... hmm, guess i'm going to have to try and get some assistance from the remote people.... unless anyone has any other ideas? Link to comment https://forums.phpfreaks.com/topic/30521-simplexml-and-xml-from-a-remote-server/#findComment-142343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.