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

Getting the data you need from the API raw response - 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

Inspection of the output screenshot of the code (see previous section) shows a complicated type of array commonly known in PHP as a "multi-dimensional array." By analyzing this type of array we can grab our desired data from the Yahoo inbound links explorer API.

To process multi-dimensional arrays, let's first do a little thought experiment. Suppose we wish to simulate the results in the previous screenshot using a PHP code; this is essential to our understanding of these arrays, which we can analyze further to grab the required data.

Again, you might find that the outermost array starts with [ResultSet]; this is the root array. Then the root array consists of four further arrays, namely:

[totalResultsAvailable]

[firstResultPosition]

[totalResultsReturned]

[Result]

The most important data can be found in the [Result] array. For example, the array [0] is the first back link data with the following innermost arrays:

[Title]

[Url]

[ClickURL]

To simulate an equivalent PHP code that will give the array structure in the earlier screenshot, start from the innermost array and work your way to the outermost array:

<?php

//This is the innermost array that contains the title tag, Url...etc

$innerarray0= array('Title' => 'This is a title0', 'Url' => 'This is the URL0', 'ClickUrl' => 'This is the ClickUrl0');

$innerarray1= array('Title' => 'This is a title1', 'Url' => 'This is the URL1', 'ClickUrl' => 'This is the ClickUrl1');

$innerarray2= array('Title' => 'This is a title2', 'Url' => 'This is the URL2', 'ClickUrl' => 'This is the ClickUrl2');

//This is the counter array starting from 0 to 2, based on the number of results you have requested from the Yahoo explorer inbound links API

$arraycount= array(0 =>$innerarray0,1=>$innerarray1,2=>$innerarray2);

//The second outer array that contains the total number of backlinks, results, starting position

$outerarray = array('totalResultsAvailable' => 569,'firstResultPosition' => 1, 'totalResultsReturned' => 3,'Result'=> $arraycount);

//This is the outermost array [ResultSet]

$rootarray=array('ResultSet'=> $outerarray);

//PHP code to display this simulated PHP code that replicates the Yahoo explorer inbound links API response PHP array

echo '<pre>';

print_r($rootarray);

echo '</pre>';

echo '<br />';

?>

Below is the screenshot of the PHP code output:

Now the above simulated PHP code output screenshot has exactly the same array structure as the original unserialized response array of inbound links explorer API (see previous screenshot).



 
 
>>> 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: