Home arrow PHP arrow Page 2 - Getting Data from Yahoo Site Explorer Inbound Links API using PHP

Unserializing the data - PHP

In the first part of this two-part series, you learned the importance and principles of Yahoo Site Explorer's inbound links API with respect to search engine optimization. If you read that part, you should already have your application ID, which will be used in your PHP script to make API calls. Also discussed in the first part is how to formulate the GET Request URL, and how to understand the responses from the inbound links API. In this part, you will start consolidating all of those inputs and implement what you've learned using a PHP server side scripting language.

TABLE OF CONTENTS:
  1. Getting Data from Yahoo Site Explorer Inbound Links API using PHP
  2. Unserializing the data
  3. Getting the data you need from the API raw response
  4. Getting the data
By: Codex-M
Rating: starstarstarstarstar / 2
November 19, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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.



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: