shadiadiph Posted June 10, 2010 Share Posted June 10, 2010 How can I open another website owned by myself and return the xml data? I know i could do it with javascript but I'd rather do it in php with one call if possible. Been toying with this all afternoon and getting nowhere maybe just too tired been at it 15 hours today already. I have website A has data on it website B needs to send an ipaddress to site A in order for the functions on the page to populate the xml I started with fsockopen but i think its the wrong way to go about it??? Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/ Share on other sites More sharing options...
syed Posted June 10, 2010 Share Posted June 10, 2010 You can use curl but you will need the library installed. Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070289 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Thanks Syed I have curl enabled but my server has had problems accessing some pages etc you do not have permission to access this page also no ini_set allowed no pear packages my new host is driving me nuts. Are there any other ways? Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070294 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Sorry to give you an idea i need to get this xml data and pretty much preserve it in the same format if possible any ideas can curl produce such an effect in one chunk? header("Content-type: text/xml"); echo "<?xml version='1.0' encoding='ISO-8859-1'?>"; echo "<geoipdata>"; echo "<countries>$countries</countries>"; echo "<countrycode>$countrycode<countrycode>"; echo "<country>$country</country>"; echo "<states>$states</states>"; echo "<state>$state</state>"; echo "<cities>$cities</cities>"; echo "<city>$city</city>"; echo "<postal>$postal</postal>"; echo "<latitude>$latitude</latitude>"; echo "<longitude>$longitude</longitude>"; echo "<metrocode>$metrocode</metrocode>"; echo "<areacode>$areacode</areacode>"; echo "</geoipdata>"; Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070297 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Sorry not sure about this and curl I have used curl in the past to post and then preg match what's returned is there not an easier way other than preg_match sorry my only real experience with curl was hacking yahoo hotmail and gmail and a few others. Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070311 Share on other sites More sharing options...
RichardRotterdam Posted June 10, 2010 Share Posted June 10, 2010 and then preg match what's returned is there not an easier way other than preg_match simpleXML Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070312 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Thank Kat that I was looking at that earlier but are you suggesting I Curl it first right? Or I noticed there was a way of opening another site in simplexml()? Only problem is if opening it through simpleXML it's a php page not an XML page I am sure I'll get there eventually. I always do after alot of cursing and it's usually the simplest way that works right Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070324 Share on other sites More sharing options...
RichardRotterdam Posted June 10, 2010 Share Posted June 10, 2010 Is the output of the php page xml data? If so it doesn't matter. you might also want to take a look at http://www.phpfreaks.com/tutorial/handling-xml-data Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070333 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Yes the outputs in XML once the ipaddress has run through the functions I did look at the link you posted earlier quickly but It seemed focused on printing RSs feeds and basic XML data manipulation within a page from the same site if my memory is correct the problem is site a to b and my reseller acct is with ENom alot of restrictions I have php but only what I am allowed to have ouch Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070335 Share on other sites More sharing options...
RichardRotterdam Posted June 10, 2010 Share Posted June 10, 2010 check the second link I posted it shows an example of parsing a XML file on a remote server using simpleXML Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070344 Share on other sites More sharing options...
shadiadiph Posted June 10, 2010 Author Share Posted June 10, 2010 Cheers will do DJ will let you know how it works out for me 2mrw, getting some liquid stress relief right now:) I wanna get some sleep without dreaming about if statements and while loops Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070348 Share on other sites More sharing options...
jonsjava Posted June 10, 2010 Share Posted June 10, 2010 Here's a simple example for simplexml_load_file: <?php $xml = simplexml_load_file("http://www.w3schools.com/XML/note.xml"); var_dump($xml); ?> Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070512 Share on other sites More sharing options...
shadiadiph Posted June 11, 2010 Author Share Posted June 11, 2010 mm kinda got it working simplexml_load_file does not seem to work when opening a php file but fopen and fread followed by simplexml_load_string($freadvalue) seems to be working fine. The one problem I have now is how to put an array into an xml node so when read it can be read as an array? at the moment i insert the variable in the <states>$states</states> but when i read it it just says Array when i print_r it it only has a value of [0] => Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070760 Share on other sites More sharing options...
shadiadiph Posted June 11, 2010 Author Share Posted June 11, 2010 ok solved it just had to implode the array first Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070763 Share on other sites More sharing options...
shadiadiph Posted June 11, 2010 Author Share Posted June 11, 2010 thanks for all the input guys Quote Link to comment https://forums.phpfreaks.com/topic/204376-how-to-get-xml-data-from-another-website-that-i-own/#findComment-1070764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.