chrisen
Goto Top

PHP und XML Float und Double

Hallo zusammen,
ich habe ein Problem mit der Erstellung von XML Dateien mit PHP:

Und zwar gibt das erstellte XML Dokument keine Float/Double Werte aus. Woran liegt das?

$preis =  20.55;


 $test_array = array (
            $preis => 'AmmountWithTax',  
);


 $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ' . 'standalone="yes"?><root/>');  
        array_walk_recursive($test_array, array ($xml, 'addChild'));  


        $xmlAusgabe = $xml->asXML();
        $fp = fopen("files/test/Export.xml", "a+");  
        fwrite ($fp, $xmlAusgabe);

Ich bekomme immer das heraus:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<root>
<AmmountWithTax>20</AmmountWithTax>
</root>

Würde mich über eine Antwort freuen!

Grüße,

chrisen

Content-Key: 315924

Url: https://administrator.de/contentid/315924

Printed on: April 26, 2024 at 23:04 o'clock

Mitglied: 129813
Solution 129813 Sep 22, 2016 updated at 07:11:33 (UTC)
Goto Top
Float values as array keys are always truncated to integer values face-smile
https://github.com/yetzt/boxing/issues/2
http://php.net/manual/de/language.types.array.php
Only integer and string values are allowed as array keys!

So convert your float to a string value.

I would rather use the addChild-Method of the object instead of array_walk.
http://php.net/manual/de/simplexmlelement.addChild.php

Regards
Member: chrisen
chrisen Sep 22, 2016 at 07:13:38 (UTC)
Goto Top
Thank you very much!