• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

php读取csv乱码问题解决方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
<form action="erxian_cy.php" method="post" enctype="multipart/form-data">
      <table class="table_con" style="width:100%;">
        
        <tbody>
        	<tr >
        	  <td><input type="file" name="file1"  />
              <input name="t" type="hidden" value="11"></td>
            </tr>
            <tr>
              <td colspan="3" align="center" style="text-align:center; padding-bottom:10px;"><input type="submit" value=" 提 交 " class="submit" /></td>
            </tr>
        
      </table>
      </form>
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为空


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
153-PHP htmlentities函数发布时间:2022-07-10
下一篇:
docker安装php-gd库发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap