Ciao a tutti,
ho trovato una funzione che mi permette di leggere un file XML di ICEcat (sito web per le schede prodotti).
Testata in una pagina separata mi restituisce i risultati senza problemi.
Dal momento che ho necessità di intersecare i risultati che ottengo dall'XML ad un CSV, ho inserito il codice interno della funzione, nella funzione di lettura del CSV.
Facendo questo, lo script finisce in timeout, come è ovvio che sia, visto che il ciclo while che gestisce la lettura delle righe deve sorbirsi circa 2000 righe di CSV, ma se imposto di uscire dal ciclo dopo 10 passaggi, non viene visualizzato assolutamente niente e il file error_log è vuoto.
Se tolgo la lettura dell'XML, visualizzo correttamente il CSV in pochi istanti.
Posto il codice che sto utilizzando per leggere l'XML:
Codice PHP:
$data = file_get_contents('http://xxxxx:xxxxxx@data.icecat.biz/xml_s3/xml_server3.cgi?prod_id='.$codice_prodotto.';vendor='.$produttore.';lang=IT;output=productxml', false);
$xml = new SimpleXMLElement($data);
// Create arrays of item elements from the XML feed
$productPicture = $xml->xpath("//Product");
$productDescription = $xml->xpath("//ProductDescription");
$categories = $xml->xpath("//CategoryFeatureGroup");
$spec_items = $xml->xpath("//ProductFeature");
$short_desc = $xml->xpath("//SummaryDescription");
$ean = $xml->xpath("//EANCode");
//Draw product specifications table if any specs available for the product
if($spec_items != null) {
$categoryList = array();
foreach($categories as $categoryitem) {
$catId = intval($categoryitem->attributes());
$titleXML = new SimpleXMLElement($categoryitem->asXML());
$title = $titleXML->xpath("//Name");
$catName = $title[0]->attributes();
//echo $catId . $catName['Value']. "
";
$categoryList[$catId] = $catName['Value'];
}
if($short_desc != null) {
foreach ($short_desc as $descrizione_breve) {
$descrizione_breve = $descrizione_breve->ShortSummaryDescription;
if($descrizione_breve !== "" || $descrizione_breve != null) {
$descrizione_breve = "[b]$codice_prodotto[/b] - $descrizione_breve";
} else {
$descrizione_breve = "[b]$codice_prodotto[/b]";
}
}
}
/* if($ean != null) {
foreach ($ean as $ean_upc) {
$ean_upc = $ean_upc->EANCode;
$specs .= "[b]EAN/UPC:[/b]";
$specs .= "$ean_upc
";
}
} */
$descrizione_lunga = "<table style='border:1px solid black;border-collapse:collapse'>";
$i = 0;
$drawnCategories = array();
foreach($spec_items as $item) {
$specValue = $item->attributes();
$titleXML = new SimpleXMLElement($item->asXML());
$title = $titleXML->xpath("//Name");
$specName = $title[0]->attributes();
$specCategoryId = intval($specValue['CategoryFeatureGroup_ID']);
if($specName['Value'] != "Source data-sheet") {
$class = $i%2==0?"odd":"even";
if(!in_array($specCategoryId, $drawnCategories))
{
$descrizione_lunga .= " <tr>
<td colspan='2' style='background-color: #afeeee; border:1px solid #a52a2a'><h3>".$categoryList[$specCategoryId]."</h3></td>
</tr>";
$drawnCategories[$i] = $specCategoryId;
}
$descrizione_lunga .= "<tr>
<td style='background-color:#f5f5f5; border:1px solid #a52a2a'>".$specName['Value'].":</td>
<td style='border:1px solid #a52a2a'>";
if($specValue['Presentation_Value'] == "Y")
{
$descrizione_lunga .= "Sì [img]check_green.png[/img]";
}
else if($specValue['Presentation_Value'] == "N")
{
$descrizione_lunga .= "No [img]check_red.png[/img]";
}
else
{
$descrizione_lunga .= str_replace('\n', '
', $specValue['Presentation_Value']);
}
$descrizione_lunga .= "</td>
</tr>";
}
$i++;
}
$descrizione_lunga .= "</table>
";
//Draw product description and link to manufacturer if available
if( $drawdescription != 0) {
foreach($productDescription as $item) {
$productValues = $item->attributes();
if($productValues['LongDesc'] != null) {
$description = str_replace('\n', '', $productValues['LongDesc']);
$description = str_replace('[b]', '[b]', $description);
$description = str_replace('[B]', '[b]', $description);
$description = str_replace('[/b]', '[/b]', $description);
$descrizione_lunga .= "
".$description;
}
}
}
}
?>
Faccio qualche errore grossolano di cui non mi accorgo?
Grazie!