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.
blog comments powered by Disqus |
|
|
|
|
|
|
|