|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-08-07 15:59 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: cmb
[2018-08-07 15:59 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 04 08:00:01 2025 UTC |
Description: ------------ Hi, just ran into this interesting bug, unsure if it effects other PHP versions. In the test case below you can see that stripped XML parsed differently than those which are separated by newlines. Test script: --------------- <?php // no indenting and new lines $xmlStr = <<<HERE <?xml version='1.0' encoding='UTF-8'?><ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0"><ns2Rates><ns2Rate UnitMultiplier="1" /><ns2Rate UnitMultiplier="1"><ns2TPA_Extensions><ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S"><ns2SupplementDescription Name="*replaced*" /></ns3AccomSupplement><ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S"><ns2SupplementDescription Name="Child Extra Bed" /></ns3AccomSupplement></ns2TPA_Extensions></ns2Rate></ns2Rates><ns2RoomRateDescription Name="Buffet Breakfast" /><ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" /></ns2RoomRate> HERE; $xml = simplexml_load_string($xmlStr); echo '<pre>'; print_r($xml); echo '</pre>'; // with indenting and new lines $xmlStr = <<<HERE <?xml version='1.0' encoding='UTF-8'?> <ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0"> <ns2Rates> <ns2Rate UnitMultiplier="1" /> <ns2Rate UnitMultiplier="1"> <ns2TPA_Extensions> <ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S"> <ns2SupplementDescription Name="*replaced*" /> </ns3AccomSupplement> <ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S"> <ns2SupplementDescription Name="Child Extra Bed" /> </ns3AccomSupplement> </ns2TPA_Extensions> </ns2Rate> </ns2Rates> <ns2RoomRateDescription Name="Buffet Breakfast" /> <ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" /> </ns2RoomRate> HERE; $xml = simplexml_load_string($xmlStr); echo '<pre>'; print_r($xml); echo '</pre>'; // no indenting and new lines BUT inserting new lines after! $xmlStr = <<<HERE <?xml version='1.0' encoding='UTF-8'?><ns2RoomRate RatePlanCode="DEF" RatePlanID="0:5:0:0"><ns2Rates><ns2Rate UnitMultiplier="1" /><ns2Rate UnitMultiplier="1"><ns2TPA_Extensions><ns3AccomSupplement AmountAfterTax="109.59" AmountBeforeTax="109.59" BestDiscountGrpNo="0" Compulsory="false" CurrencyCode="USD" ItemRPH="0:5:0:0S0S"><ns2SupplementDescription Name="*replaced*" /></ns3AccomSupplement><ns3AccomSupplement AmountAfterTax="0.00" AmountBeforeTax="0.00" BestDiscountGrpNo="0" Compulsory="true" CurrencyCode="USD" ItemRPH="0:5:0:0S1S"><ns2SupplementDescription Name="Child Extra Bed" /></ns3AccomSupplement></ns2TPA_Extensions></ns2Rate></ns2Rates><ns2RoomRateDescription Name="Buffet Breakfast" /><ns2Total AmountAfterTax="86.52" AmountBeforeTax="86.52" CurrencyCode="USD" /></ns2RoomRate> HERE; $xmlStr = str_replace('><', '>'."\n".'<', $xmlStr); // inserting here $xml = simplexml_load_string($xmlStr); echo '<pre>'; print_r($xml); echo '</pre>'; Expected result: ---------------- SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) ) Actual result: -------------- SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [0] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) ) SimpleXMLElement Object ( [@attributes] => Array ( [RatePlanCode] => DEF [RatePlanID] => 0:5:0:0 ) [ns2Rates] => SimpleXMLElement Object ( [ns2Rate] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [UnitMultiplier] => 1 ) [ns2TPA_Extensions] => SimpleXMLElement Object ( [ns3AccomSupplement] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 109.59 [AmountBeforeTax] => 109.59 [BestDiscountGrpNo] => 0 [Compulsory] => false [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S0S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => *replaced* ) ) ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 0.00 [AmountBeforeTax] => 0.00 [BestDiscountGrpNo] => 0 [Compulsory] => true [CurrencyCode] => USD [ItemRPH] => 0:5:0:0S1S ) [ns2SupplementDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Child Extra Bed ) ) ) ) ) ) ) ) [ns2RoomRateDescription] => SimpleXMLElement Object ( [@attributes] => Array ( [Name] => Buffet Breakfast ) ) [ns2Total] => SimpleXMLElement Object ( [@attributes] => Array ( [AmountAfterTax] => 86.52 [AmountBeforeTax] => 86.52 [CurrencyCode] => USD ) ) )