博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php读取csv乱码问题解决方法
阅读量:7308 次
发布时间:2019-06-30

本文共 1202 字,大约阅读时间需要 4 分钟。

if($_POST){
     $file1 = $_FILES["file1"]; $csv_file = fopen($file1["tmp_name"], 'r'); while(!feof($csv_file))$csv_result[] = fgetcsv_reg($csv_file); print_r($csv_result); foreach($result as $k=>$item){ }}function fgetcsv_reg(&$handle, $length = null, $d = ',', $e = '"') { $d = preg_quote($d); $e = preg_quote($e); $_line = ""; $eof=false; while ($eof != true) { $_line .= (empty ($length) ? fgets($handle) : fgets($handle, $length)); $itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy); if ($itemcnt % 2 == 0) $eof = true; } $_csv_line = preg_replace('/(?: |[ ])?$/', $d, trim($_line)); $_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '|[^' . $d . ']*)' . $d . '/'; preg_match_all($_csv_pattern, $_csv_line, $_csv_matches); $_csv_data = $_csv_matches[1]; for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) { $_csv_data[$_csv_i] = preg_replace('/^' . $e . '(.*)' . $e . '$/s', '$1', $_csv_data[$_csv_i]); $_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]); } return empty ($_line) ? false : $_csv_data;}

fgetcsv_reg 替代 fgetcsv 防止php读取csv出现乱码

只有 type="file" 没有其他任何东西,$_POST为空

转载于:https://www.cnblogs.com/microtiger/p/9680602.html

你可能感兴趣的文章
对于冒泡算法的思考,大牛可一笑而过~~
查看>>
IPC之命名管道
查看>>
git上传代码到osc@git
查看>>
C/C++——C++变量的作用域与生命周期,C语言中变量的作用域和生命周期
查看>>
commonJs
查看>>
RUP(Rational Unified Process)说明与模板(中文、英文)
查看>>
CMMI5个等级和22个过程域(转)
查看>>
C#中的隐藏方法
查看>>
Python之路——Python基础三
查看>>
hdu 1849 Rabbit and Grass
查看>>
HTTP协议
查看>>
Print之modile, level
查看>>
[vijos P1531] 食物链
查看>>
SUBLIME TEXT 2中,光标移入移出括号的快捷键设置
查看>>
weak_ptr<T>智能指针
查看>>
Linux-配置虚拟IP
查看>>
MUI --- 多个页面之间的传值 A页面B 页面 C页面
查看>>
[LeetCode][Java] N-Queens II
查看>>
【Android】Android聊天机器人实现
查看>>
ArcEngine 地图导航 查找路径 经纬度坐标导航 最优路径分析
查看>>