Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    Versione php e parser xml

    Stò perdendo tempo e non riesco a capire come la funzione sotto riportata funziona benissimo su Php 5.3.3 mentre non va sulla 5.2.6
    Codice PHP:
        function getICEcatProductSpecs($ean$drawdescription 0$drawpicture 0)     {         // Username and password for usage with ICEcat     $username = "Your ICEcat username goes here";     $password = "Your ICEcat password goes here";           // Return 0 and exit function if no EAN available     if($ean == null)     {     return 0;     }           // Get the product specifications in XML format     $context = stream_context_create(array(     'http' => array(     'header' => "Authorization: Basic " . base64_encode($username.":".$password)     )     ));     $data = file_get_contents('http://data.icecat.biz/xml_s3/xml_server3.cgi?ean_upc='.$ean.';lang=nl;output=productxml', false, $context);     $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");           //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'];     }           $specs = "<table class='productspecs'>";     $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";     $specs .= "<tr class='".$class."'>     <td>     <table>";     if(!in_array($specCategoryId, $drawnCategories))     {     $specs .= " <tr class='speccategory'>     <th><h3>".$categoryList[$specCategoryId]."</h3></th>     </tr>";     $drawnCategories[$i] = $specCategoryId;     }     $specs .= " <tr>     <th>".utf8_decode($specName['Value']).":</th>     </tr>     <tr>     <td>";     if($specValue['Presentation_Value'] == "Y")     {     $specs .= "Ja [img]".SCRIPT_ROOT."images/check_green.png[/img]";     }     else if($specValue['Presentation_Value'] == "N")     {     $specs .= "Nee [img]".SCRIPT_ROOT."images/check_red.png[/img]";     }     else     {     $specs .= str_replace('\n', '
    ', utf8_decode($specValue['Presentation_Value']));     }     $specs .= "</td>     </tr>     </table>     </td>     </tr>";     }     $i++;     }     $specs .= "</table>";           //Draw product description and link to manufacturer if available     if( $drawdescription != 0)     {     foreach($productDescription as $item) {     $productValues = $item->attributes();     if($productValues['URL'] != null)     {     $specs .= "<p id='manufacturerlink'>[url='".$productValues[']Productinformation from manufacturer[/url]</p>";     }     if($productValues['LongDesc'] != null)     {     $description utf8_decode(str_replace('\n'''$productValues['LongDesc']));     $description str_replace('[b]''[b]'$description);     $description str_replace('[B]''[b]'$description);     $description str_replace('[/b]''[/b]'$description);     $specs .= "<p id='manudescription'>".$description."</p>";     }     }     }           //Draw product picture if available     if( $drawdescription != 0)     {     foreach($productPicture as $item) {     $productValues = $item->attributes();     if($productValues['HighPic'] != null)     {     $specs .= "<div id='manuprodpic'>[img]".$productValues[[/img]</div>";     }     }     }     return $specs;     }     else     {     return 0;     }     } 

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    1,453
    Potresti almeno degnarti di postare la funzione come si deve, comunque la vera domanda è

    Perché vuoi usare una versione inferiore se con la 5.3.3 ti funziona?

  3. #3
    Perchè la versione sul sever produttivo è la 5.2.2. Riposto la funzione con copia incolla in quanto col tag PHP mi viene tutto in una linea.

    function getICEcatProductSpecs($ean, $drawdescription = 0, $drawpicture = 0)
    {
    // Username and password for usage with ICEcat
    $username = "Your ICEcat username goes here";
    $password = "Your ICEcat password goes here";

    // Return 0 and exit function if no EAN available
    if($ean == null)
    {
    return 0;
    }

    // Get the product specifications in XML format
    $context = stream_context_create(array(
    'http' => array(
    'header' => "Authorization: Basic " . base64_encode($username.":".$password)
    )
    ));
    $data = file_get_contents('http://data.icecat.biz/xml_s3/xml_server3.cgi?ean_upc='.$ean.';lang=nl;output=pr oductxml', false, $context);
    $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");

    //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'];
    }

    $specs = "<table class='productspecs'>";
    $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";
    $specs .= "<tr class='".$class."'>
    <td>
    <table>";
    if(!in_array($specCategoryId, $drawnCategories))
    {
    $specs .= " <tr class='speccategory'>
    <th><h3>".$categoryList[$specCategoryId]."</h3></th>
    </tr>";
    $drawnCategories[$i] = $specCategoryId;
    }
    $specs .= " <tr>
    <th>".utf8_decode($specName['Value']).":</th>
    </tr>
    <tr>
    <td>";
    if($specValue['Presentation_Value'] == "Y")
    {
    $specs .= "Ja [img]".SCRIPT_ROOT."images/check_green.png[/img]";
    }
    else if($specValue['Presentation_Value'] == "N")
    {
    $specs .= "Nee [img]".SCRIPT_ROOT."images/check_red.png[/img]";
    }
    else
    {
    $specs .= str_replace('\n', '
    ', utf8_decode($specValue['Presentation_Value']));
    }
    $specs .= "</td>
    </tr>
    </table>
    </td>
    </tr>";
    }
    $i++;
    }
    $specs .= "</table>";

    //Draw product description and link to manufacturer if available
    if( $drawdescription != 0)
    {
    foreach($productDescription as $item) {
    $productValues = $item->attributes();
    if($productValues['URL'] != null)
    {
    $specs .= "<p id='manufacturerlink'>Productinformation from manufacturer</p>";
    }
    if($productValues['LongDesc'] != null)
    {
    $description = utf8_decode(str_replace('\n', '', $productValues['LongDesc']));
    $description = str_replace('[b]', '[b]', $description);
    $description = str_replace('', '', $description);
    $description = str_replace('
    ', '
    ', $description);
    $specs .= "<p id='manudescription'>".$description."</p>";
    }
    }
    }

    //Draw product picture if available
    if( $drawdescription != 0)
    {
    foreach($productPicture as $item) {
    $productValues = $item->attributes();
    if($productValues['HighPic'] != null)
    {
    $specs .= "<div id='manuprodpic'>[img]".$productValues[[/img]</div>";
    }
    }
    }
    return $specs;
    }
    else
    {
    return 0;
    }
    }

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    1,453
    okey comunque non va non vuol dire nulla, hai aggiunto un error_reporting(E_ALL) per
    vedere tutti gli errori, oppure se utilizzi qualche funzione non presente in esso?

    Oppure cos'è che non va e che non ti da errore?

  5. #5
    Ho aggiunto come prima riga:
    error_reporting(E_ALL);

    ma non mi segnala nessun errore. Ripeto che sulla versione 5.3.3 funziona

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    1,453
    Originariamente inviato da vecchiofrack
    Ho aggiunto come prima riga:
    error_reporting(E_ALL);

    ma non mi segnala nessun errore. Ripeto che sulla versione 5.3.3 funziona
    Si ma cos'è che NON funziona nella funzione? Hai dato una controllata?

  7. #7
    La funzione carica una scheda in formato xml da un url e fa un parsing con simpleXML e stampa a video i dati. Credo che il problema sia qui:

    $xml = new SimpleXMLElement($data);

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2012
    Messaggi
    1,453
    Originariamente inviato da vecchiofrack
    La funzione carica una scheda in formato xml da un url e fa un parsing con simpleXML e stampa a video i dati. Credo che il problema sia qui:

    $xml = new SimpleXMLElement($data);
    http://it2.php.net/manual/en/simplex....construct.php (PHP 5 >= 5.0.1)

  9. #9
    Ok, darò un'occhiata

  10. #10
    Ho risolto, con php 5.3.3 richiamavo la funzione:
    function getICEcatProductSpecs($ean, $drawdescription=1 , $drawpicture=1 )
    così:
    getICEcatProductSpecs(5032037036153);
    e funzionava ma non sulla 5.2.6
    Ho risolto così:
    $ean='5032037036153';
    getICEcatProductSpecs($ean);
    Grazie anche per il tuo aiuto Ro Team

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.