Reputation: 53
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?
Upvotes: 1
Views: 60
Reputation: 1135
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
Upvotes: 1