Am getting: Parse error: syntax error, unexpected T_DNUMBER

$post_xml = "<?xml version="1.0" encoding="utf-8"?><PesapalDirectOrderInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Amount="".$order_total."" Description="".$transaction_details."" Code="".$code."" Type="".$type."" PaymentMethod="".$payment_method."" Reference="".$reference."" FirstName="".$first_name."" LastName="".$last_name."" Email="".$email."" PhoneNumber="".$phonenumber."" UserName="".$username."" xmlns="http://www.pesapal.com" />";

$post_xml = htmlentities($post_xml);

If I use single quotes the error dissappears but it does not function the way i would like it to.

How about posting the code within code tags the next time to make it easier to understand.

You have double quotes embedded in your string. How is the poor PHP interpreter supposed to make sense of this since you can't nest strings within strings? You can change the embedded quotes to single quotes as long as there are no variables between the single quotes. The more general purpose solution is to escape all of the nested quotes so they will not be treated as the end of the whole string. Thus (as an example):

$post_xml = "... version=\"1.0\" encoding=\"utf-8\" ... ";

will work. This may not be your only problem but it will fix the problem with the quotes.

Member Avatar for diafol
$post_xml = '<?xml version="1.0" encoding="utf-8"?><PesapalDirectOrderInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Amount="'.$order_total.'" Description="'.$transaction_details.'" Code="'.$code.'...

etc

works
or you can backslash double quotes as chris states. The backslash has the advantage that you don't need to concatenate the variables:

$post_xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PesapalDirectOrderInfo xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" Amount=\"$order_total\" Description=\"$transaction_details\" Code=\"$code\"...

Thanks alot guys, The script finally worked through your help, I will be glad to help where I can

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.