Skip to Content
Yahoo! Hacks
book

Yahoo! Hacks

by Paul Bausch
October 2005
Intermediate to advanced
489 pages
12h 2m
English
O'Reilly Media, Inc.
Content preview from Yahoo! Hacks

Program Yahoo! with PHP 5

Take advantage of some of the latest features in PHP to quickly add Yahoo! data to PHP-powered pages.

The recursively named PHP Hypertext Processor language is a popular choice for building dynamic web applications. In fact, Yahoo! itself has made PHP its development platform of choice across the company. The PHP platform is continually evolving, and the latest version (Version 5) includes a handy XML parser called SimpleXML. As the name implies, it’s easy to work with. And as long as the XML that SimpleXML is parsing is fairly simple, it’s the perfect tool for getting XML data into objects PHP can easily manipulate.

Yahoo! Search Web Services responses definitely qualify as simple XML, and this hack shows how easy it is to request and parse this data with PHP. You’ll need PHP 5 for this hack, but you won’t need any external modules.

The Code

Save the following code to your web server in a file called yahoo_search.php.

Tip

Don’t forget to grab a unique application ID for this script at http://developer.yahoo.net.

<?php // yahoo_search.php // Accepts a search term and shows the top results. // Usage: yahoo_search.php?p=<Query> // // You can create an AppID, and read the full documentation // for Yahoo! Web Services at http://developer.yahoo.net/ // Set your unique Yahoo! Application ID $appID = "insert your app ID"; // Grab the incoming search query, and encode for a URL $query = $_GET['p']; $query = urlencode($query); if ($query == "") { print "usage: yahoo_search.php?p=&lt;Query&gt;"; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally

Publisher Resources

ISBN: 0596009453Supplemental ContentErrata Page