-5

I heard that you can parse information from a web page with SimpleXML.

How can I get the the Usernames and ID's from the following page and display them on my website like:

Username:Napolien

Id:2202591

The URL to the website from which I want to get the information is:

http://api.roblox.com/users/3/friends

Xerx
  • 3
  • 2
  • possible duplicate of [How do you parse and process HTML/XML in PHP?](http://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Quentin Jul 25 '13 at 12:46

2 Answers2

0

The data is actually JSON. You can get it like this :

 $jsonString = file_get_content('http://api.roblox.com/users/3/friends');
 $data = json_decode($jsonString, true);

 $username = $data[14]['username']; // 14 is your desired index
 $id = $data[14]['id'];
Brewal
  • 8,067
  • 2
  • 24
  • 37
0

Your api returns json, you can decode it with json_decode, i have also include how to traverse through the json objects included in the feed.

$json = file_get_contents("http://api.roblox.com/users/3/friends");
$obj = json_decode($json);

for ($i=0; $i < count($obj); $i++) {
   echo $obj[$i]->Id;
   echo $obj[$i]->Username;
}
DevZer0
  • 13,433
  • 7
  • 27
  • 51