Problem reading UTF-8 text from excel files

Discussion in 'PHP' started by NoamBarz, Mar 16, 2008.

  1. #1
    I need to read excel files and load the data into a database.
    I decided to save the files as xml spreadsheets b/c it made reading the data much easier.
    However, I've been having trouble reading text in languages other than English. The files I use display the text correctly, but something must be going wrong during the read action.

    This is what my code looks like:

    
    if(move_uploaded_file($_FILES['pricefile']['tmp_name'],$path)){
        $dom = new DomDocument('1.0');
        $dom->_defaultEncoding = 'iconv';
        $dom->load(basename($_FILES['pricefile']['name']));
        if($dom){
          $rows = $dom->getElementsByTagName('Row');
          $i=0;
          foreach($rows as $row){
            
            if($i>0){ // ignore first line
              $index = 1;
              $cells = $row->getElementsByTagName( 'Cell' );
              
              foreach( $cells as $cell ){
                $ind = $cell->getAttribute( 'Index' );
                if ( $ind != null ) $index = $ind;
                
                if ( $index == 1 ) $prc = $cell->nodeValue;
                if ( $index == 2 ) $sup = $cell->nodeValue;
                if ( $index == 3 ) $stg = $cell->nodeValue;
                if ( $index == 4 ) $type = $cell->nodeValue;
                if ( $index == 5 ) $st = $cell->nodeValue;
                if ( $index == 6 ) $en = $cell->nodeValue;
                if ( $index == 7 ) $eq = $cell->nodeValue;
                if ( $index == 8 ) $cst = $cell->nodeValue;
                if ( $index == 9 ) $p1 = $cell->nodeValue;
                if ( $index == 10 ) $p2 = $cell->nodeValue;
                if ( $index == 11 ) $p3 = $cell->nodeValue;
                if ( $index == 12 ) $p4 = $cell->nodeValue;
                if ( $index == 13 ) $p5 = $cell->nodeValue;
                if ( $index == 14 ) $d1 = $cell->nodeValue;
                if ( $index == 15 ) $d2 = $cell->nodeValue;
                if ( $index == 16 ) $d3 = $cell->nodeValue;
                if ( $index == 17 ) $d4 = $cell->nodeValue;
                if ( $index == 18 ) $d5 = $cell->nodeValue;
                
                $index++;
              }
            }
            $i++;
            
            AddRecord($prc, $sup, $stg, $type, $st, $en, $eq, $cst, $p1, $p2, $p3, $p4, $p5, $d1, $d2, $d3, $d4, $d5);
          }
        }
      }
    
    PHP:
    can anyone help?
     
    NoamBarz, Mar 16, 2008 IP