1

I have a php code with XML structure

$bookreq =<<<XML
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Header>
<AuthenticationSoapHeader xmlns='http://epowerv5.amadeus.com.tr/WS'>
<WSUserName>****</WSUserName>
<WSPassword>****</WSPassword>
</AuthenticationSoapHeader>
</soap:Header>
<soap:Body>
<BookFlight xmlns='http://epowerv5.amadeus.com.tr/WS'>
<OTA_AirBookRQ RecommendationID='0' CombinationID='0'>
<POS />
<TravelerInfo>

--------HERE CODE--------

</TravelerInfo>
<Fulfillment>
<DeliveryAddress>
<AddressLine>Amadeus Rezervasyon Dağıtım Sistemleri A.Ş.</AddressLine>
<AddressLine>Muallim Naci Caddesi No.41 Kat 4 Ortaköy</AddressLine>
<CityName>Istanbul</CityName>
<CountryName Code='TR' />
<PostalCode>34345</PostalCode>
</DeliveryAddress>
<PaymentDetails>
<PaymentDetail PaymentType='None'>
<BillingAddress>
<AddressLine>Amadeus Rezervasyon Dağıtım Sistemleri A.Ş.</AddressLine>
<AddressLine>Muallim Naci Caddesi No.41 Kat 4 Ortaköy</AddressLine>
<CityName>Istanbul</CityName>
<CountryName Code='TR' />
<PostalCode>34345</PostalCode>
</BillingAddress>
</PaymentDetail>
</PaymentDetails>
<PaymentText Name='TripName' Text='Payment text' />
<PaymentText Name='Notes' Text='Payment notes' />
</Fulfillment>
<Ticketing TicketType='BookingOnly'/>
</OTA_AirBookRQ>
</BookFlight>
</soap:Body>
</soap:Envelope>
XML";

I need paste code

for($a=1;$a<=$adtpass;++$a)
{
  $adtblock;
}

Here --------HERE CODE--------

When I paste this code in xml structure, I have error

Parse error: syntax error, unexpected 'for' (T_FOR).

How can I add this piece of code to the XML code that will be correct?

After Donald123 comment, rewrite my code

$bookreq = <<<XML
<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>
<soap:Header>
<AuthenticationSoapHeader xmlns='http://epowerv5.amadeus.com.tr/WS'>
<WSUserName>****</WSUserName>
<WSPassword>****</WSPassword>
</AuthenticationSoapHeader>
</soap:Header>
<soap:Body>
<BookFlight xmlns='http://epowerv5.amadeus.com.tr/WS'>
<OTA_AirBookRQ RecommendationID='0' CombinationID='0'>
<POS />
<TravelerInfo>
XML;
for($a=1;$a<=$adtpass;++$a)
{
    echo $adtblock;
}
<<<XML
</TravelerInfo>
<Fulfillment>
<DeliveryAddress>
<AddressLine>Amadeus Rezervasyon Dağıtım Sistemleri A.Ş.</AddressLine>
<AddressLine>Muallim Naci Caddesi No.41 Kat 4 Ortaköy</AddressLine>
<CityName>Istanbul</CityName>
<CountryName Code='TR' />
<PostalCode>34345</PostalCode>
</DeliveryAddress>
<PaymentDetails>
<PaymentDetail PaymentType='None'>
<BillingAddress>
<AddressLine>Amadeus Rezervasyon Dağıtım Sistemleri A.Ş.</AddressLine>
<AddressLine>Muallim Naci Caddesi No.41 Kat 4 Ortaköy</AddressLine>
<CityName>Istanbul</CityName>
<CountryName Code='TR' />
<PostalCode>34345</PostalCode>
</BillingAddress>
</PaymentDetail>
</PaymentDetails>
<PaymentText Name='TripName' Text='Payment text' />
<PaymentText Name='Notes' Text='Payment notes' />
</Fulfillment>
<Ticketing TicketType='BookingOnly'/>
</OTA_AirBookRQ>
</BookFlight>
</soap:Body>
</soap:Envelope>
XML;

This is what i have done, whether such code work, when I put variable $bookreq in my cURL request?

3
  • 2
    read about heredoc php.net/manual/en/… Commented Dec 2, 2016 at 9:37
  • I don't understand, what you want. If you have a php file and want to insert some php-code, then open an editor and do it. By the way there is an error in your second code. After the code you inserted you need to write: "$bookreq1 .= <<<XML" - to append it to the existing variable. That php script will by itself not ouput anything. If you want to output the xml, you need to echo $bookreq1 at the end of the script. Commented Dec 2, 2016 at 10:44
  • I not need echo my code, I need when I paste for-loop in this xml structure, then can use $bookreq in curl request Commented Dec 2, 2016 at 10:55

1 Answer 1

1

You can make another PHP file to generate the full XML source, like in http://pastebin.com/nU9ZRuCD

Then in the main PHP file, you do include:

<?php

ob_start();
require 'my-xml-generator.php';
$bookreq = ob_get_contents();
ob_end_clean();


echo $bookreq;

Or use a template engine, example Twig: http://twig.sensiolabs.org/doc/intro.html

Sign up to request clarification or add additional context in comments.

3 Comments

and then I can use $bookreq in my cURL request?
Yes, all the content of the generated include (require) will be in the $bookreq.
Thaks for help,Rogeriolino

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.