bravo14 Posted March 13, 2011 Share Posted March 13, 2011 Hi Guys I have got a page generating the following error Error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/sites/trade-bidz.co.uk/public_html/functions/reg_functions.php on line 3 The offending code is below (I have removed some of the URL due to security. <?php function getVehData(){ $file="https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=$_POST['veh_reg']"; $dom=new DOMdocument(); $dom->load($file); $xml=simplexml_import_dom($dom); echo('<tr><td>Make<td></td></tr> <tr><td>Model<td></td></tr> <tr><td>Make<td></td></tr> <tr><td>Date of Manufacture<td></td></tr> <tr><td>First Registered<td></td></tr> <tr><td>Colour<td></td></tr> <tr><td>Body<td></td></tr> <tr><td>No. of Doors<td></td></tr> <tr><td>Engine Size (cc)<td></td></tr> <tr><td>Fuel Type<td></td></tr> <tr><td>Gearbox Type<td></td></tr> <tr><td>Previous Owners<td></td></tr> <tr><td>BHP<td></td></tr> <tr><td>Emissions<td></td></tr> </table> '); } ?> Link to comment https://forums.phpfreaks.com/topic/230502-unexpected-t_encapsed_and_whitespace-expecting-t_string-or-t_variable-or-t_num/ Share on other sites More sharing options...
gristoi Posted March 13, 2011 Share Posted March 13, 2011 try: you need to concatenate the post variable into the string: ".$_POST['veh_reg']." $file="https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=".$_POST['veh_reg'].""; looks like your $_POST['veh_reg'] isnt escaping properly in the string. Link to comment https://forums.phpfreaks.com/topic/230502-unexpected-t_encapsed_and_whitespace-expecting-t_string-or-t_variable-or-t_num/#findComment-1186929 Share on other sites More sharing options...
silkfire Posted March 13, 2011 Share Posted March 13, 2011 When embedding array variable element into a string you need to omit the inner single quotes in its brackets: $file = "https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm=$_POST[veh_reg]"; Link to comment https://forums.phpfreaks.com/topic/230502-unexpected-t_encapsed_and_whitespace-expecting-t_string-or-t_variable-or-t_num/#findComment-1186940 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2011 Share Posted March 13, 2011 You can also use curly brackets to surround the array reference: <?php $file = "https://www.cdlvis.com/lookup/getxml?username=***********&mode=test&key=*********&vrm={$_POST['veh_reg']}"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/230502-unexpected-t_encapsed_and_whitespace-expecting-t_string-or-t_variable-or-t_num/#findComment-1186944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.