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

Getting 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

Based on the previous section's analysis of PHP code, you can easily grab important data. For example, say you need the title tag of all backlink URLs.

Let:

$display= $unserialized ['ResultSet'];

$display1=$display['Result'];

This is the command to penetrate from the outermost array to the results array, and then, by the properties of combinational array, the title tag can be called as:

$display1[$x]['Title'];

Where $x is the counter of the array (example: 0 for the first back link, and 2 for the third back link.)

The final PHP code required to make a request to the Yahoo API, grab the response and finally display the title tag of all back link URLs to the browser is as follows:

<?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=3&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>';

echo '<br />';

//DISPLAY THE TITLE TAG OF ALL BACKLINK URL

$display= $unserialized['ResultSet'];

$display1=$display['Result'];

//$display2=$display1[0]['Title'];

$x=0;

$count= sizeof($display1);

//echo $count;

while ($x < $count) {

echo $display1[$x]['Title'];

echo '<br />';

$x++;

}

?>

Take note that the WHILE loop has been used to iterate the grabbing of data from the first back links with array [0] to the maximum size of the array, determined by the sizeof() function.



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap

Dev Shed Tutorial Topics: