ue=" Go! " /> <select name="type"> <?php foreach($service as $name => $val) { if(!empty($_REQUEST['type']) && $name == $_REQUEST['type']) echo "<option SELECTED>$name</option>\n"; else echo "<option>$name</option>\n"; } ?> </select> </form> <?php function done() {?> </body></html> <?php exit; }
if(empty($_REQUEST['query']) || !in_array($_REQUEST['type'],array_keys($service))) done();
// Ok, here we go, we have the query and the type of search is valid // First build the query $q = '?query='.rawurlencode($_REQUEST['query']); if(!empty($_REQUEST['zip'])) $q.="&zip=".$_REQUEST['zip']; if(!empty($_REQUEST['start'])) $q.="&start=".$_REQUEST['start']; $q .= "&appid=$appid";
// Then send it to the appropriate service $xml = file_get_contents($service[$_REQUEST['type']].$q);
// Parse the XML and check it for errors if (!$dom = domxml_open_mem($xml,DOMXML_LOAD_PARSING,$error)) { echo "XML parse error\n"; foreach ($error as $errorline) { /* For production use this should obviously be logged to a file instead */ echo $errorline['errormessage']."<br />\n"; echo " Node : " . $errorline['nodename'] . "<br />\n"; echo " Line : " . $errorline['line'] . "<br />\n"; echo " Column : " . $errorline['col'] . "<br />\n"; } done(); }
// Now traverse the DOM with this function // It is basically a generic parser that turns limited XML into a PHP 上一页 [1] [2] [3] [4] [5] [6] 下一页 |