I want to embed FindWhat.com's XML search results into a PHP page (as a meta search engine).
I have customised the SearchHippo.com script but the problem is that the links for the search results don't work (the "clickurl" XML element) !
If anyone can help me fix this, there's a reward! 🙂 Look at the bottom of the message!
Here's the PHP script I'm using :
///////////////////////////////////////////
<body bgcolor="#fafafa" link=green>
<font face="Tahoma" size="1">
<?php
////////////////////////////////////////////////////////////////////////
//
// This page should be called with "q" as a parameter passed in through
// the url that contains the query request. For example, if you save this
// page as "searchhippo.php", you might call
// http://[your-domain]/searchhippo.php?q=searchhippo
// again, where q are the search critera.
//
// You can also pass in "c" for the number of results to produce per page.
// This is automagically limited to 50.
//
// Have fun, enjoy, and distribute freely!
//
////////////////////////////////////////////////////////////////////////
$ip_addr = GetHostByName($REMOTE_ADDR);
function startElementHandler ($parser, $element_name, $element_attribs)
{
global $recctr;
global $curstate;
global $recs;
global $qrystatus;
if ($element_name == "result") {
$qrystatus ["count"] = trim ($element_attribs ["RECORDS"]);
$qrystatus ["head"] = trim ($element_attribs ["FIRST"]);
$qrystatus ["tail"] = trim ($element_attribs ["LAST"]);
}
$curstate = $element_name;
}
function endElementHandler ($parser, $element_name)
{
global $recctr;
global $curstate;
global $recs;
$curstate = "";
if ($element_name=="RECORD") { $recctr++; }
}
function characterDataHandler ($parser, $data)
{
global $recctr;
global $curstate;
global $recs;
global $link;
global $click;
global $jumpto;
global $clickurl1;
global $clickurl2;
global $clickurl3;
global $clickurl4;
global $clickurl5;
global $clickurl6;
global $clickurl7;
global $clickurl8;
global $clickurl9;
global $clickurl10;
if ($curstate == "") return;
else if ($curstate == "BIDPRICE") { $recs [$recctr] ["bidprice"] = trim ($data); }
else if ($curstate == "CLICKURL") { $recs [$recctr] ["clickurl"] = trim ($data); }
else if ($curstate == "TITLE") { $recs [$recctr] ["title"] = trim ($data);}
else if ($curstate == "URL") { $recs [$recctr] ["url"] = trim ($data); }
else if ($curstate == "DESCRIPTION") { $recs [$recctr] ["description"] = trim ($data);}
}
// global vars
$recctr = 0; // number of records retrieved
$in_item_tag = 0; // flag for expat parsing
$curstate = ''; // for xpath state
$recs = array (); // returned data results
$jumpto = array ();
$qrystatus = array (); // returned data status
$clickurl1 = ' ';
$clickurl2 = ' ';
$clickurl3 = ' ';
$clickurl4 = ' ';
$clickurl5 = ' ';
$clickurl6 = ' ';
$clickurl7 = ' ';
$clickurl8 = ' ';
$clickurl9 = ' ';
$clickurl10 = ' ';
$xml_parser = xml_parser_create();
if (!($xml_parser)) {
die ("Cannot load XML parser!");
} else {
xml_set_element_handler ($xml_parser,
"startElementHandler",
"endElementHandler");
xml_set_character_data_handler ($xml_parser,
"characterDataHandler");
$q = stripslashes ($q);
$qenc = urlencode ($q); // q is query
$fp = fopen ("findwhat.xml", "r");
if ($fp) {
$data = fread ($fp, 40960);
while ($data) {
if (!xml_parse ($xml_parser, $data, feof ($fp))) { break; }
$data = fread ($fp, 40960);
}
}
xml_parser_free ($xml_parser);
// Now all of our data has been read from the url and parsed. We now
// have populated the two global arrays, $recs and $qrystatus.
// additionally, $recctr will have the number of results we retrieved
// (i.e. the size of the $recs array
//
if ($recctr > 0) {
// Here we are going to loop over all the items in the $recs array and
// output as necessary.
for ($x = 0; $x < $recctr; $x++) {
$y = $x + 1;
if (strlen ($recs [$x] ["title"]) > 64) {
$ShowTitle = sprintf ("%-.61s...", $recs [$x] ["title"]);
} else $ShowTitle = $recs [$x] ["title"];
if (strlen ($recs [$x] ["description"]) > 192) {
$ShowDescr = sprintf ("%-.189s...", $recs [$x] ["description"]);
} else $ShowDescr = $recs [$x] ["description"];
if (strlen ($recs [$x] ["clickurl"]) > 500) {
$Clickurl = sprintf ("%-.497s...", $recs [$x] ["clickurl"]);
} else $Clickurl = $recs [$x] ["clickurl"];
$DisplayURL = $recs [$x] ["url"];
$BidPrice = $recs [$x] ["bidprice"];
// $Clickurl = $recs [$x] ["clickurl"];
if (!$ShowTitle) $ShowTitle = $DisplayURL;
// Outputting some HTML below
/*******************************************************/
echo ("$Clickurl");
printf ("<FONT SIZE=\"-1\">%d. <A HREF=\"%s\"><B>%s</B></A></FONT><BR>",
$y, $Clickurl,
$ShowTitle);
if (strlen ($ShowDescr) > 0) {
printf ("<FONT SIZE=\"2\">%s</FONT><BR>", $ShowDescr);
}
printf ("<FONT SIZE=\"-1\" Face=\"Times New Roman\" COLOR=\"black\"><i>%s</i> - (Advertiser Paid: $%s)</FONT><BR>\n",
$DisplayURL, $BidPrice);
printf("<br>\n");
/*******************************************************/
}
printf ("%s", $Clickurl);
} else {
printf ("<CENTER><FONT SIZE=\"2\" COLOR=\"#CC1111\">Sorry, no results available for <B>\"%s\"</B></FONT></CENTER>\n", $q);
}
}
?>
///////////////////////////////////////
now this PHP inserts an XML file, like
the one below (findwhat.xml):
<?xml version="1.0" encoding="windows-1252"?>
<result status="OK" records="170" first="1" last="10" searchRequest="health" responseTime="94ms">
<record><title><![CDATA[SUPROSOY: For Health, For Life]]></title><url>http://www.suprosoy.com</url><description><![CDATA[Information about soy and soy protein, soy products, soy recipes, health benefits of soy protein and SUPROSOY, the soy protein used most clinical research studies.]]></description><bidprice>0.36</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=7539&w=46966&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[FREE Infertility Video!]]></title><url>http://www.integramed.com</url><description><![CDATA[Get a time-saving overview of the causes and treatment of infertility. Don't miss this video, it's on CD-ROM and 100% FREE! From INTEGRAMED, the infertility specialists.]]></description><bidprice>0.35</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=4318&w=27666&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[Body Weight Loss]]></title><url>http://bodyweightloss.com</url><description><![CDATA[Lose 5 lbs. per day! 10 lbs. in 2 days! Or lose up to 27 lbs. per week! Results are guaranteed. No exceptions!]]></description><bidprice>0.31</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=18658&w=136796&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[HGH For Permanent Weight Loss, Health, & Fitness]]></title><url>http://www.automateyourwebsite.com/app/adtrack.asp?AdID=3955</url><description><![CDATA[How does permanent weight loss without diets sound? Or fitness, health, energy, muscle gain, body fat loss, younger skin, better sleep? Are mild depression, menopause, blood pressure, fatigue issues? Visit us to learn about safe, affordable, HGH. ]]></description><bidprice>0.30</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=17776&w=122187&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[Getvitamins.com - Online Health Store]]></title><url>http://www.getvitamins.com</url><description><![CDATA[Buy vitamins at wholesale prices. Choose from over 12,000 health products, herbal remedies, and nutritional supplements.]]></description><bidprice>0.30</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=200&w=87002&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[High Quality Nutritional Supplements]]></title><url>http://www.pennysaved.com/</url><description><![CDATA[Products include MSM, first milking colostrum, noni, chlorella, oil of oregano, glucosamine, cetyl myristoleate, grape seed extract, ionic trace minerals, msm lotion, msm eye drops, green juice pdrs, celtic sea salt, Wobenzym N, Barlean's flax oil...]]></description><bidprice>0.25</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=11079&w=76160&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[New Balance Web Express]]></title><url>http://www.newbalancewebexpress.com</url><description><![CDATA[New Balance shoes and apparel. Large sizes andwidths (AA-6E) available. Online Foot Health Clinic and discount CloseoutSection.]]></description><bidprice>0.25</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=8045&w=59393&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[DietDivas Quick Weight Loss Diet Plan]]></title><url>http://www.dietdivas.com</url><description><![CDATA[Lose 2-5 pounds each week using real food. No pills or prepackaged meals. Free newsletter and bonus gifts. Don't wait. Join today - start today!]]></description><bidprice>0.25</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=4437&w=28681&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[Personal -development]]></title><url>http://4self-improvement.com</url><description><![CDATA[Break through limitations, realise your dreams, and change your life forever!The world leader in personal-development. ]]></description><bidprice>0.25</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=18232&w=138709&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
<record><title><![CDATA[BeautynHealth.com SkinCare & Nutrition]]></title><url>http://www.BeautynHealth.com</url><description><![CDATA[Epicuren & YonKa Skin Care, Tyson USP Pharmaceutical Grade Vitamins-Minerals-Amino Acids, Self Tanning, For Kid's: Mustela, Rhino Vites & Sunblock/Insect Repellent, Ask the Esthetician and the Nutritional Counselor your questions.]]></description><bidprice>0.21</bidprice><clickurl>http://216.216.246.30/bin/findwhat.dll?clickthrough&c=16837&w=116412&t=6865616C7468&aff_id=47038&srch_id=606F7D745B5BA87D78784A</clickurl></record>
</result>
if you save the php file and then the
XML file as "findwhat.xml" in the same folder
you can hack around. Put your mouse over any one of the links: the link is unfinished (compare with the XML file). How can I fix this?
Whoever helps me fix this bug gets a super-duper reward : free promotion! I'll link to your site(s), your picture, anything! My websites get over 4,000 visitors daily, so we can barter on this!
Thanks!