$b["BID"]) ? -1 : 1; } class clsSearch { var $current_tag; var $xml_parser; var $num_results; var $results = array(); var $tmp_title; var $tmp_description; var $tmp_clickurl; var $tmp_url; var $tmp_bidprice; function clsSearch() { $this->num_results = 0; } function buildResultsArray($epilot_url, $findwhat_url) { global $keyword; // $epilot_url = str_replace('search.epilot.com/getresults.asp', 'vasearch.epilot.com/getresults.asp', $epilot_url); // $epilot_url = str_replace('vasearch.epilot.com/getresults.asp', 'vasearch.epilot.com/getresults.aspx', $epilot_url); //echo $epilot_url.'
'; // the URL to fetch ePilot results if (!($fp = fopen($epilot_url, 'r'))) { die("Could not open $xml_file for parsing!\n*". $epilot_url."*"); } //$this->parseXml( $fp ); $data2 = ""; while ($data = fread($fp, 4096)) { if (!($data = utf8_encode($data))) { echo 'ERROR'."\n"; } $data2 .= $data; } $this->parse_diffrent($data2); // the URL to fetch Findwhat results if (!($fp = fopen($findwhat_url, 'r'))) { die("Could not open $xml_file for parsing!\n"); } $this->parseXml( $fp ); //Now lets throw more mess into this mess... // echo "KEywORD: $keyword"; if (!($fp = fopen("http://www.rocketpile.com/xml.php?category=web&per_page=8&extra_qry=&qry_str=$keyword", 'r'))) { die("Could not open $xml_file for parsing!\n"); } $data2 = ""; while ($data = fread($fp, 4096)) { if (!($data = utf8_encode($data))) { echo 'ERROR'."\n"; } $data2 .= $data; } $this->parse_diffrent2($data2); // sort the results in decending order by bid //usort($this->results, "bidCompare"); } function parseXml( $fp ) { // echo "hi"; // the tags that we want to parse // if a tag isn't in the array, it will be ignored $open_tags = array( 'RESULTS' => '', // start of epilot tags 'ROW' => '', 'SDNRESULT' => '', // start of findwhat tags 'RECORD' => '', 'CLICKURL' => '', 'URL' => '', 'DESCRIPTION' => '', 'TITLE' => '', 'BIDPRICE' => '<BIDPRICE>'); $close_tags = array( 'RESULTS' => '<RESULTS>', 'ROW' => '<ROW>', 'SDNRESULT' => '<SDNRESULT>', 'RECORD' => '<RECORD>', 'CLICKURL' => '<CLICKURL>', 'URL' => '<URL>', 'DESCRIPTION' => '<DESCRIPTION>', 'TITLE' => '<TITLE>', 'BIDPRICE' => '<BIDPRICE>'); // declare the character set - UTF-8 is the default $type = 'UTF-8'; // create our parser $this->xml_parser = xml_parser_create($type); // set some parser options xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, true); xml_parser_set_option($this->xml_parser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); // this tells PHP what functions to call when it finds an element // these funcitons also handle the element's attributes xml_set_object($this->xml_parser,&$this); $counter = 0; xml_set_element_handler($this->xml_parser, 'startElement','endElement'); // this tells PHP what function to use on the character data xml_set_character_data_handler($this->xml_parser, 'characterData'); // loop through the file and parse, baby! while ($data = fread($fp, 4096)) { if (!($data = utf8_encode($data))) { echo 'ERROR'."\n"; } // echo $data; if (!xml_parse($this->xml_parser, $data, feof($fp))) { die(sprintf( "XML error: %s at line %d\n\n", xml_error_string(xml_get_error_code($this->xml_parser)), xml_get_current_line_number($this->xml_parser))); } } xml_parser_free($this->xml_parser); } function addResult($title, $description, $urllink, $advertiserurl, $bid) { $this->results[$this->num_results] = array("TITLE" => $title, "DESCRIPTION" => $description, "URLLINK" => $urllink, "ADVERTISERURL" => $advertiserurl, "BID" => $bid); $this->num_results++; } function startElement($parser, $name, $attrs) { $this->current_tag = $name; switch (strtoupper($name)) { case "ROW": if (isset($attrs["URLLINK"])) //if (strlen($attrs["URLLINK"]) > 0) echo "ONE<br>"; $this->addResult($attrs["TITLE"], $attrs["DESCRIPTION"], $attrs["URLLINK"], $attrs["ADVERTISERURL"], $attrs["BID"]); break; default: break; } } function characterData($parser, $data) { // echo $this->current_tag."<BR>"; switch (strtoupper($this->current_tag)) { case "TITLE": $this->tmp_title .= $data; break; case "DESCRIPTION": $this->tmp_description .= $data; break; case "CLICKURL": $this->tmp_clickurl .= $data; break; case "URL": $this->tmp_url .= $data; break; case "DISPLAYURL": $this->tmp_url .= $data; break; case "YOURSHARE": $this->tmp_bidprice .= $data; case "BIDPRICE": $this->tmp_bidprice .= $data; break; } } function endElement($parser, $name, $attrs='') { global $counter; if ($name == "RECORD" && $counter < 2) { //echo "TWO<br>"; $counter++; $this->addResult($this->tmp_title, $this->tmp_description, $this->tmp_clickurl, $this->tmp_url, $this->tmp_bidprice); $this->tmp_title = ""; $this->tmp_description = ""; $this->tmp_clickurl = ""; $this->tmp_url = ""; $this->tmp_bidprice = ""; } return; } function parse_diffrent($data) { //echo $data; /* <sdnResult> <title>House Numbers - MyKnobs.com Find house numbers at MyKnobs.com. Shop for other decorative hardware, home accents, and bathroom decor items. http://vaclick.epilot.com/click.aspx?k=house&b=3600&p=looksmart4&s=getitfido&pos=1&sid=35D68159-6201-42D5-B19B-067E2809E30F&l=http%3A%2F%2Fwww.looksmart.com%2Fog%2Fpr%3DPsr%3Bro%3D3%3Brc%3D6%3Bla%3D243887%3Blm%3D147951%3Bli%3D101818171%3Bed%3D20040123%3Bii%3D78e8.13ca.429f7b54.10d506%3Bpn%3D%3Bto%3D%3Btc%3D6%3Bpo%3D3%3Bpc%3D6%3Bpi%3Depls3%3Bts%3D%7Chttp%3A%2F%2Fstore.yahoo.com%2Fcgi%2Dbin%2Fclink%3Fmyknobs%2B4UuB52%2Bhousnumonsal.html http://www.MyKnobs.com/housnumonsal.html 0.3600 0.2160 no 1 */ $tag_array_start[] = ''; $tag_array_start[] = '<description>'; $tag_array_start[] = '<clickUrl>'; $tag_array_start[] = '<displayUrl>'; $tag_array_start[] = '<grossBid>'; $tag_array_start[] = '<yourShare>'; $tag_array_start[] = '<adult>'; $tag_array_start[] = '<pos>'; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $array_one = explode('',$data); //for ($i = 1; $i < count($array_one); $i++) for ($i = 1; $i < 3; $i++) { //$array_two = expode("\n",$array_one[$i]); for ($z = 0; $z < count($tag_array_start); $z++) { $a = strpos($array_one[$i], $tag_array_start[$z]); $b = strpos($array_one[$i], $tag_array_end[$z]); $tempy = ""; if ($a === FALSE || $b === FALSE) { /// } else { $tempy = substr($array_one[$i],$a + strlen($tag_array_start[$z]),$b - ($a + strlen($tag_array_start[$z])) ); } switch ( $tag_array_start[$z] ) { case '': $temp_title = $tempy; break; case '<description>': $temp_description = $tempy; break; case '<clickUrl>': $temp_urllink = $tempy; break; case '<displayUrl>': $temp_advertiserurl = $tempy; break; case '<yourShare>': $temp_bid = $tempy; break; } } $this->addResult($temp_title, $temp_description, $temp_urllink, $temp_advertiserurl, $temp_bid); } } function parse_diffrent2($data) { //echo $data; /* <result> <follow_url>http://tmsyn.wc.ask.com/r?t=an&s=hb&uid=240f6242640f62426&sid=340f6242640f62426&qid=2B90FA7033A24648894FC473394515DF&io=0&sv=za5cb0de2&o=0&ask=pokemon&uip=40f62426&en=te&eo=-100&pt=Pokemon.com&ac=24&qs=121&pg=1&ep=1&te_par=102&te_id=&u=http://www.pokemon.com/</follow_url> <title>Pokemon.com The official Pokemon site with news about the video games, card games, books, comics, TV shows, and movies.
http://tmsyn.wc.ask.com/r?t=an&s=hb&uid=24... */ $tag_array_start[] = ''; $tag_array_start[] = ''; $tag_array_start[] = '<desc>'; $tag_array_start[] = '<trun_real_url>'; $tag_array_end[] = '</follow_url>'; $tag_array_end[] = ''; $tag_array_end[] = ''; $tag_array_end[] = ''; $array_one = explode('',$data); //for ($i = 1; $i < count($array_one); $i++) for ($i = 1; $i < 9; $i++) { //$array_two = expode("\n",$array_one[$i]); for ($z = 0; $z < count($tag_array_start); $z++) { $a = strpos($array_one[$i], $tag_array_start[$z]); $b = strpos($array_one[$i], $tag_array_end[$z]); $tempy = ""; if ($a === FALSE || $b === FALSE) { /// } else { $tempy = substr($array_one[$i],$a + strlen($tag_array_start[$z]),$b - ($a + strlen($tag_array_start[$z])) ); } switch ( $tag_array_start[$z] ) { case '': $temp_title = $tempy; break; case '<desc>': $temp_description = $tempy; break; case '<follow_url>': $temp_urllink = $tempy; break; case '<trun_real_url>': $temp_advertiserurl = $tempy; break; break; } } $this->addResult($temp_title, $temp_description, $temp_urllink, $temp_advertiserurl, $temp_bid); } } } ?>