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?
Ich bekomme immer das heraus:
Würde mich über eine Antwort freuen!
Grüße,
chrisen
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
Please also mark the comments that contributed to the solution of the article
Content-Key: 315924
Url: https://administrator.de/contentid/315924
Printed on: April 26, 2024 at 23:04 o'clock
2 Comments
Latest comment
Float values as array keys are always truncated to integer values
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
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