简体   繁体   English

PHPExcel-将奇怪的字符保存到数据库

[英]PHPExcel - Saving weird Characters to Database

I'm using PHPExcel version 1.8.0, 2014-03-02. 我正在使用PHPExcel 1.8.0,2014-03-02。

In the Excel I have this kind of cells: Ahumada nº 301 / Huérfanos 在Excel中,我具有以下单元格:Ahumada n°301 /Huérfanos

But in the database shows: Ahumada nº 301 / Huérfanos 但是在数据库中显示:Ahumada n°301 /Huérfanos

Any one knows how to fix this? 有人知道如何解决这个问题吗?

This is my code: 这是我的代码:

include 'PHPExcel/IOFactory.php';
$inputFileName = 'data.xlsx'; 

try {
    $objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} 
catch(Exception $e) {
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}

$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);

for($i=2;$i<=$arrayCount;$i++){
    $local      =   trim($allDataInSheet[$i]['A']);
    $descripcion=   trim($allDataInSheet[$i]['B']);
    $comuna     =   trim($allDataInSheet[$i]['C']);
    $region     =   trim($allDataInSheet[$i]['D']);
    $insertTable= "INSERT INTO sucursales (Numero, Direccion, Comuna, Region, ID_Cliente) VALUES('".$local."', '".$descripcion."','".$comuna."', '".$region."', '".$_POST['select_cliente2']."');";
    mysqli_query($con,$insertTable);
}

Thanks! 谢谢!

I added 我加了

mysqli_set_charset($con, "utf8")

In the connection to mysql and now is working as it should be! 在与mysql的连接中,现在应该可以正常工作了!

Thanks. 谢谢。

I found the way! 我找到了路! I just add this line in the php and everything worked! 我只是在php中添加了这一行,一切正常!

header('Content-Type: text/html; charset=utf-8');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM