1

I am trying to extract data from Facebook pages, till now I have managed to gather data from the pages in a JSON format, however I want these to be displayed in a presentable manner. Would anyone provide me with any techniques or what my next step should be?

My current code is as follows:

$pageIdPosition = strripos($_POST["URL"], '/');
$pageIdStop = strripos($_POST["URL"], '?');
$pageId = substr($_POST["URL"], $pageIdPosition +1);

echo $pageId;
echo "<br />\n";
echo "<br />\n";

// create a new cURL resource

$url = "http://graph.facebook.com/" . $pageId . "posts";

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// grab URL and pass it to the browser
curl_exec($ch);

$res = curl_exec($ch);
var_dump($res);

// close cURL resource, and free up system resources
curl_close($ch);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2675041
  • 115
  • 1
  • 5
  • 15
  • possible duplicate of [Parsing JSON file with PHP](http://stackoverflow.com/questions/4343596/parsing-json-file-with-php) – Abhishek Apr 26 '15 at 12:56

1 Answers1

3

You could add this at the bottom:

$resArr = json_decode($res, 1); // decodes the json string to an array echo $resArr['id'] // outputs the id from your json result

http://php.net/manual/en/function.json-decode.php

Andrew Larsen
  • 1,257
  • 10
  • 21