Okay, once the response has been dumped into a $response PHP variable, the data in this variable is not yet workable with PHP. This is because the data format is called "serialized," which cannot be resolved to an easy analysis. If $response variable (which is serialized) is displayed in a browser, this is how it would look:
The above raw data can be very hard to process, so in this case you will need to convert the above raw data format into an "array." One effective method involves using the " unserialize() " function. So to unserialize the data: //Step 5. Convert to unserialized $unserialized = unserialize($response); To display the unserialized array in the browser: echo '<pre>'; print_r($unserialized); echo '</pre>'; And finally, the completed basic PHP script, which will make a request, grab the response and convert to appropriate data format for processing (using the unserialized PHP function) will be: <?php //Step 1. Report possible errors for debugging error_reporting(E_ALL); //Step 2. Declare the request variable $request='http://search.yahooapis.com/SiteExplorerService/V1/inlinkData?appid=TrnTAC3V34FlhDKeOScqpmw42Tu8B4BI8VUI7awsdcvfYIjJDwbtnb4rfNmmeQ--&query=http://www.php-developer.org&results=50&output=php'; //Step 3. Read the responses from Yahoo inbound links API and put into a string. $response = file_get_contents($request); //Step 4 if ($response === false) { die('The request fails.'); } //Step 5. Convert to unserialized $unserialized = unserialize($response); //Step 6. To display the array in the browser: echo '<pre>'; print_r($unserialized); echo '</pre>'; ?> So when the script is executed, it now uses a PHP array, which is easy to use and manipulate with your applications (see the screenshot below):
Note this is still raw data. An additional script is required to grab related data for analysis.
blog comments powered by Disqus |
|
|
|
|
|
|
|