我正在为电子商务网站制作导入/导出功能。导入库存运行良好的功能。但那里存在问题。当我在库存字段中写入任何特殊字符(例如“。”,“,”)时,此字符将替换为“??”。
那么,任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
header( "Content-Type: text/html; charset=utf-8");
$csvContent = file_get_contents( $fileName );
$encoding = mb_detect_encoding( $csvContent,
array("UTF-8","UTF-32","UTF-32BE","UTF-32LE","UTF-16","UTF-16BE","UTF-16LE"),
TRUE );
if( $fileEncoding !== "UTF-8" ) {
$csvContent = mb_convert_encoding($csvContent, "UTF-8", $fileEncoding );
}
foreach( explode( PHP_EOL, $csvContent ) as $item ) {
var_dump($item );
}