3v4l.org

run code in 300+ PHP versions simultaneously
<?php $csv = <<<'CSV' produit nom_pdf type_pdf prive_pdf 1 ENTREE_AIR_AUTO_RE_FR_FR_28143161 Rapport_d_essai 0 1 M_FT_FR_FR_201803 Fiche_technique 0 100 AMD+C_FT_FR_FR_201901 Fiche_technique 0 1000 APDR_FT_FR_FR_201907 Fiche_technique 0 1000 ATTESTATION_A1_CONVENTIONNELS Procès-verbal 1 CSV; $lines = explode("\n", $csv); $headers = str_getcsv(array_shift($lines), ' '); $xw = new XMLWriter(); $xw->openMemory(); $xw->startDocument("1.0", "utf-8"); $xw->setIndent(true); $xw->setIndentString(' '); $xw->startElement('Products'); $prevprod = false; foreach ( $lines as $line ) { $data = array_combine($headers, str_getcsv($line, ' ')); if ( $data['produit'] !== $prevprod ) { if ( $prevprod ) $xw->endElement(); $prevprod = $data['produit']; $xw->startElement('produit'); $xw->writeAttribute('code', $data['produit']); } $xw->startElement('Fichier'); $xw->writeAttribute('nom_fichier', $data['nom_pdf']); $xw->writeAttribute('type_fichier', $data['type_pdf']); $xw->writeAttribute('prive', $data['prive_pdf']); $xw->endElement(); } $xw->endElement(); // product (last) $xw->endElement(); // Products $xw->endDocument(); echo $xw->outputMemory();
Output for 8.4.1 - 8.4.13
Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 15 Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 27 Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 27 Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 27 Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 27 Deprecated: str_getcsv(): the $escape parameter must be provided as its default value will change in /in/tiN94 on line 27 <?xml version="1.0" encoding="UTF-8"?> <Products> <produit code="1"> <Fichier nom_fichier="ENTREE_AIR_AUTO_RE_FR_FR_28143161" type_fichier="Rapport_d_essai" prive="0"/> <Fichier nom_fichier="M_FT_FR_FR_201803" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="100"> <Fichier nom_fichier="AMD+C_FT_FR_FR_201901" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="1000"> <Fichier nom_fichier="APDR_FT_FR_FR_201907" type_fichier="Fiche_technique" prive="0"/> <Fichier nom_fichier="ATTESTATION_A1_CONVENTIONNELS" type_fichier="Procès-verbal" prive="1"/> </produit> </Products>
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.26
<?xml version="1.0" encoding="UTF-8"?> <Products> <produit code="1"> <Fichier nom_fichier="ENTREE_AIR_AUTO_RE_FR_FR_28143161" type_fichier="Rapport_d_essai" prive="0"/> <Fichier nom_fichier="M_FT_FR_FR_201803" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="100"> <Fichier nom_fichier="AMD+C_FT_FR_FR_201901" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="1000"> <Fichier nom_fichier="APDR_FT_FR_FR_201907" type_fichier="Fiche_technique" prive="0"/> <Fichier nom_fichier="ATTESTATION_A1_CONVENTIONNELS" type_fichier="Procès-verbal" prive="1"/> </produit> </Products>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <?xml version="1.0" encoding="UTF-8"?> <Products> <produit code="1"> <Fichier nom_fichier="ENTREE_AIR_AUTO_RE_FR_FR_28143161" type_fichier="Rapport_d_essai" prive="0"/> <Fichier nom_fichier="M_FT_FR_FR_201803" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="100"> <Fichier nom_fichier="AMD+C_FT_FR_FR_201901" type_fichier="Fiche_technique" prive="0"/> </produit> <produit code="1000"> <Fichier nom_fichier="APDR_FT_FR_FR_201907" type_fichier="Fiche_technique" prive="0"/> <Fichier nom_fichier="ATTESTATION_A1_CONVENTIONNELS" type_fichier="Procès-verbal" prive="1"/> </produit> </Products>

preferences:
127.46 ms | 413 KiB | 5 Q