Click here to Skip to main content
15,998,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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>&pound;".$car->price."/day</b><br>Unlimited Miles</td></tr>";
}
echo "</table>";
?>


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
Posted
Updated 12-Sep-11 0:56am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900