我正在尝试上传一个CSV并将其内容保存在数据库中以备稍后处理。CSV文件的某个位置恰好有一个ASCII字符。这是CSV 中的一个单元格
inflatable?ÿtavel?ÿpillow
现在,当尝试使用PHP(准确地说是cakeHP)将此文件读取到数据库中时,file_get_contents()
会忽略第一个ÿ
之后的所有内容
$fh = fopen($_FILES['uploadedFile']['tmp_name'], 'rb');
$this->request->data['ChannelUpload']['data'] = file_get_contents($_FILES['uploadedFile']['tmp_name']);
查看php.net:
<?php
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content, 'UTF-8, ISO-8859-1', true));
}
?>