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

    Problema pardon XML con php e caratteri speciali

    ciao a tutti.
    stò sbattendo la teasta da ormai due giorni su questo parser xml fatto in php.
    _
    funziona tutto bene ma, quando all'interno di un tag incontro una lettera accentata o una parentesi o un'apice ecc mi tronca il dato:
    _
    per esempio:
    _
    _
    il prodotto non é disponibile:
    output: il prodotto non
    _
    non riesco a trovare una soluzione.
    vi posto lo script.

    Codice PHP:
      <?php   class Content_Handler {      function Content_Handler(){}      function start_element($parser$name$attrs) {        global $print_characters;        if ($name == "PRODUCT"){           $zupid = ($attrs["ZUPID"]);           echo "$zupid
    "
    ;        }        if ($name == "NAME" || $name == "DESCRIPTION" || $name == "DEEPLINK") {           $print_characters true;        }    }      function end_element($parser$name) {        if ($name == "PRODUCT") {           print "
    "
    ;        }    }      function characters($parser$chars) {        global $print_characters;        if ($print_characters) {                                 echo "$chars
    "
    ;           $print_characters false;        }    } }           $print_characters false;   $handler = new Content_Handler(); $book_parser xml_parser_create("UTF-8");   xml_parser_set_option($book_parserXML_OPTION_TARGET_ENCODING"UTF-8"); xml_set_object($book_parser$handler); xml_set_element_handler($book_parser"start_element""end_element"); xml_set_character_data_handler($book_parser"characters");     $file "mio.xml";     if ($file_stream fopen($file"r")) {      while ($data fread($file_stream4096)) {          $this_chunk_parsed xml_parse($book_parser$datafeof($file_stream));        if (!$this_chunk_parsed) {            $error_code xml_get_error_code($book_parser);            $error_text xml_error_string($error_code);            $error_line xml_get_current_line_number($book_parser);              $output_text "Parsing problem at line $error_line$error_text";            die($output_text);        }    } } else {       die("Can't open XML file.");   } xml_parser_free($book_parser);
    www.boardingstore.it

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2009
    Messaggi
    26
    Prova ad utilizzare la funzione utf8_decode().

    In alternativa, prendi in considerazione questa libreria http://www.bin-co.com/php/scripts/xml2array/index.php.

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.