Home Backend Development PHP Tutorial php文件读写有关问题

php文件读写有关问题

Jun 13, 2016 am 10:16 AM
explode output quot var

php文件读写问题
T,T
源代码是这样的。。。。
@$fp = fopen($_FILES["file"]["tmp_name"],"r");
if($fp){
  while (!feof($fp)) {
$count++;
$output = fgets($fp, 1024);
$var = explode(",", $output);
。。。。。。
}
奇怪的是,第一行的信息总是缺少的,
文件内容是:71222237, 计算机, JAVA数据库编程, 清华大学出版社, 2003, 孙林, 39, 7
然后读出来,$var[0] = 7122223
这是为什么呀。。。。。。

------解决方案--------------------
完整的var 是什么情况?var_dump
------解决方案--------------------
@$fp = fopen($_FILES["file"]["tmp_name"],"r");
if($fp){
while (!feof($fp)) {
$count++;
$output = fgets($fp, 1024);
echo base64_encode($output);
exit;
$var = explode(",", $output);
。。。。。。
}

代码中加入红色的那两句,执行后贴出结果
------解决方案--------------------

探讨

引用:

@$fp = fopen($_FILES["file"]["tmp_name"],"r");
if($fp){
while (!feof($fp)) {
$count++;
$output = fgets($fp, 1024);
echo base64_encode($output);
exit;
$var = explode(",", $out……

------解决方案--------------------
探讨
额,那样有什么用,我的文件编码应该是正确的,因为第二行开始结果是对的额。。。

------解决方案--------------------
好吧,你看看是为什么
PHP code
echo $output = base64_decode("77u/NzgyMjExMjIsIOiuoeeul+acuiwgSkFWQeaVsOaNruW6k+e8lueoiywg5riF5Y2O5aSn5a2m5Ye654mI56S+LCAyMDAzLCDlrZnmnpcsIDM5LCA3DQo=");$var = explode(",", $output);print_r($var);<br><font color="#e78608">------解决方案--------------------</font><br>那就要考虑 BOM 了<br>你的数据文件是 utf-8 的并且有 BOM 头<br>print_r(unpack('H*', $output));<br><br>Array<br>(<br>   [1] => efbbbf3738323231...<br>)<br><br>你在处理第一行时把 BOM 同去掉试试<br>$var = explode(",", substr($output, 3));<br><br><br><font color="#e78608">------解决方案--------------------</font><br>BOM 头不在所指示的字符集中,对于字符集而言属于非法字符,当然要影响正常的数据啦<br><br>比如用 iconv 在做编码转换时,遇到非法字符时不是就截断了吗?<br><div class="clear">
                 
              
              
        
            </div>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use PHP explode function and solve errors How to use PHP explode function and solve errors Mar 10, 2024 am 09:18 AM

The explode function in PHP is a function used to split a string into an array. It is very common and flexible. In the process of using the explode function, we often encounter some errors and problems. This article will introduce the basic usage of the explode function and provide some methods to solve the error reports. 1. Basic usage of the explode function In PHP, the basic syntax of the explode function is as follows: explode(string$separator,string$stri

Common errors and solutions when using the explode function in PHP Common errors and solutions when using the explode function in PHP Mar 11, 2024 am 08:33 AM

Title: Common errors and solutions when using the explode function in PHP In PHP, the explode function is a common function used to split a string into an array. However, some common errors can occur due to improper use or incorrect data format. This article will analyze the problems you may encounter when using the explode function, and provide solutions and specific code examples. Mistake 1: The delimiter parameter is not passed in. When using the explode function, one of the most common mistakes is that the delimiter parameter is not passed in.

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

18 Ways to Fix Audio Service Not Responding Issue on Windows 11 18 Ways to Fix Audio Service Not Responding Issue on Windows 11 Jun 05, 2023 pm 10:23 PM

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

Let's talk about the differences between var, let and const (code example) Let's talk about the differences between var, let and const (code example) Jan 06, 2023 pm 04:25 PM

This article brings you relevant knowledge about JavaScript. It mainly introduces the differences between var, let and const, as well as the relationship between ECMAScript and JavaScript. Interested friends can take a look at it. I hope Helpful to everyone.

The role and examples of var keyword in PHP The role and examples of var keyword in PHP Jun 28, 2023 pm 08:58 PM

The role and examples of var keyword in PHP In PHP, the var keyword is used to declare a variable. In previous PHP versions, using the var keyword was the idiomatic way to declare member variables, but its use is no longer recommended. However, in some cases, the var keyword is still used. The var keyword is mainly used to declare a local variable, and the variable will automatically be marked as local scope. This means that the variable is only visible within the current block of code and cannot be accessed in other functions or blocks of code. Use var

Split and merge strings using the explode and implode functions Split and merge strings using the explode and implode functions Jun 15, 2023 pm 08:42 PM

In PHP programming, processing strings is a frequently required operation. Among them, splitting and merging strings are two common requirements. In order to perform these operations more conveniently, PHP provides two very practical functions, namely the explode and implode functions. This article will introduce the usage of these two functions, as well as some practical skills. 1. The explode function The explode function is used to split a string according to the specified delimiter and return an array. Its function prototype is as follows: arra

Front-end output settings Front-end output settings Feb 19, 2024 am 09:30 AM

Front-end output configuration requires specific code examples. In front-end development, output configuration is a very important configuration. It is used to define the file path, file name and related resource paths generated after the project is packaged. This article will introduce the role of front-end output configuration, common configuration options, and give specific code examples. The role of output configuration: The output configuration item is used to specify the file path and file name generated after the project is packaged. It determines the final output of the project. Packaged in webpack etc.

See all articles