I improvised a code that reads the XML files of a folder, one after another, and retrieves the information of some specific fields (title and summary), and I want to pass this information to a file CSV to one row per file (one column with titles and another with summaries).
Here it is complete:
<?php
$fp = fopen("C:/*****/PHP/METADAT.csv","a");
$directorio = ('C:/Users/***/xml');
$ficheros1 = scandir($directorio);
$ficheros1 = array_diff($ficheros1,array('.','..'));
$cantidad = count($ficheros1);
$i = 2;
while ($i <= $cantidad):
$carga = simplexml_load_file('C:/Users/***/xml');
/*acceder a las rutas XML que nos interesan (XPATH)*/
$titulo = $carga->xpath(
'/MD_Metadata/identificationInfo/MD_DataIdentification/citation/CI_Citation/title'
);
$resumen = $carga->xpath('/MD_Metadata/identificationInfo/MD_DataIdentification/abstract');
/*volcar el contenido en CSV*/
$lista[$i] = array($titulo,$resumen);
$i++;
endwhile; //fin del bucle while
foreach ($lista as &$campos) {
fputcsv($fp, $campos);
}
fclose($fp);
?>
The problem is that the fputcsv($fp,$campos)
creates a CSV that contains the word Array many times, because when doing data loading in $titulo
and% % co considers them objects $resumen
or something like that inside they have the desired information, when I really only want the textual value contained in 'title' and 'abstract' from within my XML .
Can I recover that value in some simple way?