本质上,我目前想解析从 html 生成的 XML 数据,这工作正常,但由于某种原因现在无法解析......给出 1970 年 1 月 1 日的日期??......任何关于编码问题的想法似乎美好的?
提前非常感谢!
<?php
//ini_set("disable_functions",null);
//phpinfo();
$string="http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote";
$string.="&xloc=".$_REQUEST["loccode"];
$string.="&xlocname=".$_REQUEST["locname"];
$string.="&xlocdrop=".$_REQUEST["locdrop"];
$string.="&xbook=".$_REQUEST["book"];
$string.="&xonewaystart=".$_REQUEST["onewaystart"];
$string.="&xonewayend=".$_REQUEST["onewayend"];
$string.="&xpuyear=".date("Y",strtotime($_POST['pickup_date']));
$string.="&xpumonth=".date("m",strtotime($_POST['pickup_date']));
$string.="&xpuday=".date("d",strtotime($_POST['pickup_date']));
$string.="&xputime=".$_REQUEST["pu_time"];
$string.="&xdbyear=".date("Y",strtotime($_POST['return_date']));
$string.="&xdbmonth=".date("m",strtotime($_POST['return_date']));
$string.="&xdbday=".date("d",strtotime($_POST['return_date']));
$string.="&xdbtime=".$_REQUEST["db_time"];
$string.="&xclass=".$_REQUEST["vehicle_type"];
echo "<!-- $string -->";
function get_data($url)
{
echo $url;
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
//echo get_data($string);
$xmlDoc=simplexml_load_string ( get_data($string) ) ;
/*
function proxy_url($proxy_url)
{
$proxy_name = '127.0.0.1';
$proxy_port = 4001;
$proxy_cont = '';
$proxy_fp = fsockopen($proxy_name, $proxy_port);
if (!$proxy_fp) {return false;}
fputs($proxy_fp, "GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n\r\n");
while(!feof($proxy_fp)) {$proxy_cont .= fread($proxy_fp,4096);}
fclose($proxy_fp);
$proxy_cont = substr($proxy_cont, strpos($proxy_cont,"\r\n\r\n")+4);
return $proxy_cont;
}
echo proxy_url($string);*/
function XML2Array ( $xml , $recursive = false )
{
if ( ! $recursive )
{
$array = simplexml_load_string ( $xml ) ;
}
else
{
$array = $xml ;
}
$newArray = array () ;
$array = ( array ) $array ;
foreach ( $array as $key => $value )
{
$value = ( array ) $value ;
if ( isset ( $value [ 0 ] ) )
{
$newArray [ $key ] = trim ( $value [ 0 ] ) ;
}
else
{
$newArray [ $key ] = XML2Array ( $value , true ) ;
}
}
return $newArray ;
}
function disp_date($str)
{
$y=substr($str,0,4);
$m=substr($str,4,2);
$d=substr($str,6,2);
//echo $y."-".$m."-".$d;
return date("M d, Y",strtotime($y."-".$m."-".$d));
}
$handle = fgets($string, "r");
$xml_string="";
// If there is something, read and return
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$xml_string.=$buffer;
}
fclose($handle);
}
//$xmlDoc = new DOMDocument();
//echo "xml string = " . $xml_string;
?></div>
<div class="box">
<?
//print_r($xmlDoc);
echo "<br><strong/>Pick up Location: ".$xmlDoc->hire->loccode."<br> Drop-off Location: ".$xmlDoc->hire->locdrop."<br>Pickup Time: ".disp_date($xmlDoc->hire->pickupdate)." ".$xmlDoc->hire->pickuptime."<br>Dropback Time: ".disp_date($xmlDoc->hire->dropbackdate)." ".$xmlDoc->hire->dropbacktime."<br>";
echo "<table border=1 style='font:12px verdana' cellspacing=0 cellpadding=3><tr><td>Car Type</td><td>Description</td><td>Rate</td></tr>";
foreach($xmlDoc->car as $car)
{
$url = $car->book;
$url = str_replace('wheels4rent.net', '', '$url');
echo "<!-- url = $car->book -->";
echo "<tr><td width=200px><img src='".$car->carimage."' align='left' style='padding:1px; width:100px'><b>".$car->cartype."</b><br>".$car->carsipp."<br>".$car->transmission."</td><td><b>".$car->carexample."</b></td><td><b>£".$car->price."
</b><br>Unlimited Miles</b><br>
<input type=button onclick=\"javascript:newWin('".trim($car->book)."');\" value='Prepay Now'></td></tr>";
}
echo "</table>";
?>