php文件读写有关问题
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);
。。。。。。
}
代码中加入红色的那两句,执行后贴出结果
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
好吧,你看看是为什么
- 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>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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

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

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 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

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 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.
