PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 25th, 2013, 11:00 PM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old January 25th, 2013, 11:10 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,861 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 45 m 34 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
PHP Code:
 $xml = new SimpleXMLElement("http://that thing"0true); 

should get you started.

Reply With Quote
  #3  
Old January 26th, 2013, 12:12 AM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 22 sec
Reputation Power: 0
that has definitely taken me on the right path - thanks!

Reply With Quote
  #4  
Old January 26th, 2013, 01:21 AM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old January 26th, 2013, 02:17 AM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,861 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 45 m 34 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
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); 

Reply With Quote
  #6  
Old January 26th, 2013, 10:33 AM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 33 m 22 sec
Reputation Power: 0
very interesting - thanks - Ill give it a try today - you rock!

Reply With Quote
  #7  
Old January 26th, 2013, 11:19 AM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old January 26th, 2013, 02:43 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Dec 2004
Posts: 8,052 E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 1 Day 5 h 6 m 34 sec
Reputation Power: 7104
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.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #9  
Old January 26th, 2013, 02:47 PM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old January 26th, 2013, 03:19 PM
RobMichaelson RobMichaelson is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 7 RobMichaelson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - GET cross domain proxy to display in html

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap