Essentially, I currently have XML data that is generated from a URL but want this converted to a table. For some reason does not work. have also enabled PHP error finding and comes up with following :
Warning: simplexml_load_string(): Entity: line 2: parser error : XML declaration allowed only at the start of the document in /customers/f/4/2/wheels4rent.net/httpd.www/list_car1.php on line 43 Warning: simplexml_load_string(): in /customers/f/4/2/wheels4rent.net/httpd.www/list_car1.php on line 43 Warning: simplexml_load_string(): ^ in /customers/f/4/2/wheels4rent.net/httpd.www/list_car1.php on line 43 Warning: fgets() expects parameter 1 to be resource, string given in /customers/f/4/2/wheels4rent.net/httpd.www/list_car1.php on line 100
The URL that generates the XML is:
<a href="http://www.thrifty.co.uk/cgi-bin/gen5?runprog=thxml&xsrc=7qhfqou3&mode=quote&xloc=AI001&xlocname=&xlocdrop=&xbook=&xonewaystart=&xonewayend=&xpuyear=2013&xpumonth=08&xpuday=12&xputime=09:00&xdbyear=2013&xdbmonth=08&xdbday=19&xdbtime=09:00&xclass=M
This URL should place XML content into a table from list_car1.php as shown below but nothing happens...please check www.wheels4rent.net and enter dates to see problem
<?php
$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;
}
$xmlDoc=simplexml_load_string ( get_data($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);
return date("M d, Y",strtotime($y."-".$m."-".$d));
}
$handle = fgets($string, "r");
$xml_string="";
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
$xml_string.=$buffer;
}
fclose($handle);
}
?></div>
<div class="box">
<?
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'>".$car->cartype."<br>".$car->carsipp."<br>".$car->transmission."</td><td>".$car->carexample."</td><td>£".$car->price."
<br>Unlimited Miles<br>
<input type=button önclick=\"javascript:newWin('".trim($car->book)."');\" value='Prepay Now'></td></tr>";
}
echo "</table>";
?>