从xml生成的代码中提取CDATA [英] extracting CDATA from xml generated code
问题描述
我有以下网站URL,即http://www.wheels4rent.net/test00.html
输入数据后,会从XML生成PHP,并在下面给出XML
示例
您可以通过以下电话获得报价:location UK001(Heathrow)10/10/2011 09:00-12/10/2011 10:00仅限手动车
http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote&xloc=UK001&
amp; xpuyear = 2011& xpumonth = 10& xpuday = 10& xputime =
09:00& xdbyear = 2011& xdbmonth = 10& xdbday = 12& xdbtime = 10:00&
xclass = M
这将给出指定位置的汽车列表,我已经使用php做到了这一点.您可以从www.wheels4rent.net/test00.html查看结果,并输入位置和日期.
当单击"go"按钮时,可以从list_car.php中检索数据.list_car.php如下所示.
I have following website URL which is http://www.wheels4rent.net/test00.html
When data is entered a PHP is generated from XML and example given below of XML
You can get a quotation with a call like this: location UK001 (Heathrow) 10/10/2011 09:00 - 12/10/2011 10:00 Manual cars only
http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote&xloc=UK001&
amp;xpuyear=2011&xpumonth=10&xpuday=10&xputime=
09:00&xdbyear=2011&xdbmonth=10&xdbday=12&xdbtime=10:00&
xclass=M
This will give a list of cars at the specified location and i have done this ok using php. You can see result from www.wheels4rent.net/test00.html and put in location and date.
From this one can retrieve data from list_car.php when ''go'' button clicked.list_car.php is shown below.
<?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.="&xpuyear=".substr($_REQUEST["pu_month"],0,4);
$string.="&xpumonth=".substr($_REQUEST["pu_month"],4);
$string.="&xpuday=".$_REQUEST["pu_day"];
$string.="&xputime=".$_REQUEST["pu_time"];
$string.="&xdbyear=".substr($_REQUEST["db_month"],0,4);
$string.="&xdbmonth=".substr($_REQUEST["db_month"],4);
$string.="&xdbday=".$_REQUEST["db_day"];
$string.="&xdbtime=".$_REQUEST["db_time"];
$string.="&xclass=".$_REQUEST["vehicle_type"];
/*
function get_data($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);
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 = fopen($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();
$xmlDoc=simplexml_load_string ( $xml_string ) ;
//print_r($xmlDoc);
echo "Zipcode: ".$xmlDoc->hire->loccode."<br>Location Name: ".$xmlDoc->hire->locname."<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)
{
echo "<tr><td width=150px><img src='".$car->carimage."' align='right' style='padding:5px; width:64px'><b>".$car->cartype."</b><br>".$car->carsipp."<br>".$car->transmission."</td><td><b>".$car->carexample."</b></td><td><b>£".$car->price."/day</b><br>Unlimited Miles</td></tr>";
}
echo "</table>";
?>
从http://www.wheels4rent.net/list_car.php,我获取了所有必需的信息,除了我需要的预订按钮之外,当预订了特定汽车时,会给出CDATA信息,但目前尚不确定如何集成CDATA .任何指针,将不胜感激. CDATA信息位于< book> XML部分(单击第一个链接以查看)
Andrew
From the http://www.wheels4rent.net/list_car.php i have all the required info except a booking button which i require and when a particular car is booked then the CDATA info is given but unsure how to integrate the CDATA at present. Any pointers would be appreciated. The CDATA info is in the <book> section of the XML(click on 1st link given to view)
Andrew
推荐答案
string = " ;
string="http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote";
string.= & xloc =".
string.="&xloc=".
_REQUEST [ loccode"];
_REQUEST["loccode"];
这篇关于从xml生成的代码中提取CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!