';
echo 'Search for ';
// If there is a query
if(!empty($_GET['q']))
{
echo '';
// IMPORTANT: FILL IN THESE FIELDS
//////////////////////////////////////////////////////////////////////////////////////
// Yahoo AppID - get one by registering at http://developer.yahoo.com/search/boss
$appid = 'LD_EaibV34GL1X1CGfDRzy5BhhdVLwV0CBxe4H3MNtIxlR8HySAQ9DUFKUNG2NE8ZUGkkd0XUA--';
// Comma-separated list of domains to search in
$domains = 'marcovitanza.com';
//////////////////////////////////////////////////////////////////////////////////////
// Main part of BOSS query URL - note the "web/" for web pages only
$pre = 'http://boss.yahooapis.com/ysearch/web/v1/';
// Set the current result page. Specific page may be requested from a Next or Prev link
$results_per_page = 10;
$page = intval($_GET['page']);
if($page < 1)
$page = 1;
// Partial query paramaters. Format can also be JSON.
$params = '&format=xml&sites=' . $domains . '&count=' . $results_per_page . '&start=' . (($page - 1) * $results_per_page);
// Initialize our CURL session with the BOSS query URL
$ch = curl_init($pre . urlencode($_GET['q']) . '?appid=' . $appid . $params);
// We want the XML data to be returned (not echoed) so we can parse it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the CURL request to retrieve the search results in XML format
// By default, there will be a maximum of 10 results in one XML response
// You can change this value and the result offset (for page 2, 3...) by adding more query paramaters
// See BOSS documentation for more details
$xml = curl_exec($ch);
curl_close($ch);
// variables for storing data from the XML
$curtag = $y_link = $y_abstract = $y_title = '';
// result counters
$i = ($page - 1) * $results_per_page + 1;
$totalhits = 0;
// XML PARSING FUNCTIONS
/////////////////////////////////////////////////////////////////////////////////////////
// The parser found a start tag for an element
function start_tag($parser, $name, $attribs)
{
global $curtag, $totalhits;
// Save the current tag name so we know where we are
$curtag = $name;
// Get the total hits from the tag
if($curtag == 'RESULTSET_WEB')
$totalhits = intval($attribs['TOTALHITS']);
}
// The parser found some character data inside an element
function tag_data($parser, $data)
{
global $curtag, $y_link, $y_abstract, $y_title;
// If we are inside an or tag, save the data for display later
// If you want the default keyword highlighting (bold) then don't strip_tags()
if($curtag == 'ABSTRACT')
$y_abstract = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
elseif($curtag == 'TITLE')
$y_title = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
elseif($curtag == 'URL')
$y_link = htmlentities(strip_tags($data), ENT_QUOTES, 'UTF-8');
}
// The parser found an end tag for an element
function end_tag($parser, $name)
{
global $curtag, $y_link, $y_abstract, $y_title, $i;
// If this is the end of a element
if($name == 'RESULT')
{
// Echo the result listing with URL, title, and abstract
echo '
';
// Reset the temporary data vars
$y_link = '';
$y_abstract = '';
$y_title = '';
// Increment result counter
$i++;
}
// Reset the current tag name
$curtag = '';
}
/////////////////////////////////////////////////////////////////////////////////////////
// Create an XML parser
$parser = xml_parser_create();
// Setup our handler functions so the parser calls them when it finds tags and data
xml_set_element_handler($parser, 'start_tag', 'end_tag');
xml_set_character_data_handler($parser, 'tag_data');
// Parse the search results XML. The results will be printed by the functions above
// Remember, $xml is the variable where the XML data was stored from the CURL response
xml_parse($parser, $xml);
// Write the Prev and Next page links
echo '