The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP5 - GET cross domain proxy to display in html
Discuss GET cross domain proxy to display in html in the PHP Development forum on Dev Shed. GET cross domain proxy to display in html PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 25th, 2013, 11:00 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
|
PHP5 - GET cross domain proxy to display in html
Hello
I am having a hell of a time grabbing a URL ttp://184.173.18.228/api/profile/1000/0/Adam.Adams that is XML when viewed in the browser - the idea is that when a user updates their profile (on another site) it will update ( also) on our site.. I have tried everything to get that url into php to echo on page - I was able to display the xml info on a page when the xml was local on my machine with jQuery but we need to use PHP ( I guess)
Can anyone show me how to do this? using a cross domain proxy script (?) CURL? Im lost - how hard would it be for someone to grab that url and at least display one node? for me for example code? Im not a PHP guy but we need this feature on our site - thanks
Rob
|

January 25th, 2013, 11:10 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
PHP Code:
$xml = new SimpleXMLElement("http://that thing", 0, true);
should get you started.
|

January 26th, 2013, 12:12 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
|
that has definitely taken me on the right path - thanks!
|

January 26th, 2013, 01:21 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
Im really close but I get the same error no matter which code I try
Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found in /code/5wTn3P on line 5
Warning: SimpleXMLElement::__construct(): {"ProfileSections":[{"SectionType":"ContactCard","Sections":[{"ContentType":"Pro in /code/5wTn3P on line 5
Warning: SimpleXMLElement::__construct(): ^ in /code/5wTn3P on line 5
and the code being along these lines-
Code:
<?php // Load XML $url = "http://184.173.18.228/api/profile/1000/0/Adam.Adams"; $string = file_get_contents($url); $xml = new SimpleXMLElement($string); // Get the entries $entries = $xml->entry; foreach($entries as $e){ // Get each entriy's id $id = $e->id; // Get the attributes // ID is in the "im" namespace $attr = $id->attributes('im', TRUE); // echo id echo $attr['id'].'<br/>'; } ?>
a few version of this btw
Im getting the feeling that the API a dev guy gave me is bad
any help is appreciated
R
|

January 26th, 2013, 02:17 AM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
The site does some sort of content type negotiation: your browser would rather see XML so it sends XML, but without that indication it sends JSON by default.
So forget XML and use
PHP Code:
$json = json_decode($string);
|

January 26th, 2013, 10:33 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
|
very interesting - thanks - Ill give it a try today - you rock!
|

January 26th, 2013, 11:19 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
|
can you point me to a page that has an example of decoding an api like my example? seems liek every example is using an array instead
thanks a million
R
|

January 26th, 2013, 02:43 PM
|
 |
Lost in code
|
|
|
|
|
json_decode decodes the response and turns it into an array. If you don't know the format of the array, use the var_dump function on it.
|

January 26th, 2013, 02:47 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
I think I got it! thsi code shoots output - the output Ive been waiting for - any idea how to slap it onto a page that I can style? - it outputs what looks like to me an array - I need that array into something I can format
Code:
<?php $url="http://184.173.18.228/api/profile/1000/0/Adam.Adams"; $json = file_get_contents($url,0,null,null); $json_output = json_decode($json); echo '<pre>'; print_r("query results:"); print_r($json_output); '</pre>'; foreach ( $json_output->data->items as $data ){ echo "{$data->id}"; echo "{$data->title}"; } ?>
thanks for help in advance
Rob
|

January 26th, 2013, 03:19 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 7
Time spent in forums: 33 m 22 sec
Reputation Power: 0
|
|
|
thanks! var dump - yeah, been seeing that
if you can see this page http://callison.netau.net/proxy4.php that is what I managed to produce
so I can see the array ( that is an array correct?)
thanks for you help
R
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|