Home Backend Development PHP Tutorial 新人提问:不明白ftell()解决思路

新人提问:不明白ftell()解决思路

Jun 13, 2016 am 10:32 AM
data exa fgets ftell

新人提问:不明白ftell()
$fp = fopen('exa', 'r');

$data = fgets($fp, 15);

echo ftell($fp);

fclose($fp);
?>

这个例子中输出:13
若15改成1046之类的比较大的数,也输出13;
若15改成13,则输出12


究竟是怎么回事呢?

------解决方案--------------------
首先,你的'exa'文件这一行的指针宽度是13,而指针起始是从0开始,因此当你选择15或者更大的时候,只要超过本身宽度,那么只能输出最大的宽度,也就是13.
其次,由于指针是从0开始算的,所以$data = fgets($fp, num);,而指针实际是从0开始,那么ftell($fp)的值肯定是num-1,比如你fgets($fp, 5),那么ftell($fp)就会是4。
所以你“若15改成13,则输出12”,是因为13没有超过最大宽度,因此输出的是13-1。

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1653
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
The reason why php fgets ignores the newline character at the end of the line and its solution The reason why php fgets ignores the newline character at the end of the line and its solution Mar 20, 2023 pm 04:12 PM

PHP is a popular programming language used for developing web applications and dynamic websites. When processing file input, the fgets() function is typically used to read a line of text from a file. However, sometimes the fgets() function ignores newline characters at the end of a line, which can lead to program errors and unpredictable results. In this article, we will explore the causes and solutions to this problem.

Introduction to PHP functions—fgets(): Read a line from a file Introduction to PHP functions—fgets(): Read a line from a file Jul 24, 2023 pm 12:54 PM

Introduction to PHP functions—fgets(): Read a line from a file In PHP, many functions are provided for reading and writing files. Among them, the fgets() function is one of the functions used to read the content line by line from the file. This article will introduce the fgets() function and demonstrate its usage through code examples. The fgets() function is one of the file input functions in PHP, used to read a line of content from a file. Its basic syntax is as follows: stringfgets(resource$ha

How to install and use exa on Linux system? How to install and use exa on Linux system? Mar 01, 2024 pm 06:31 PM

To install and use exa on a Linux system, you can follow these steps: Open Terminal: In Linux systems, press the Ctrl+Alt+T key combination to open the terminal. Download exa: exa is a modern ls replacement tool that provides a more beautiful and feature-rich file listing. Enter the following command in the terminal to download exa: wget This command will download the compressed file of exa from GitHub. Decompress exa: Use the following command to decompress the downloaded exa compressed file: unzipexa-linux-x86_64-0.10.1.zip After decompression, an executable file named exa will be generated. Install exa: Copy the exa file to the system's

What data is in the data folder? What data is in the data folder? May 05, 2023 pm 04:30 PM

The data folder contains system and program data, such as software settings and installation packages. Each folder in the Data folder represents a different type of data storage folder, regardless of whether the Data file refers to the file name Data or the extension. Named data, they are all data files customized by the system or program. Data is a backup file for data storage. Generally, it can be opened with meidaplayer, notepad or word.

What to do if mysql load data is garbled? What to do if mysql load data is garbled? Feb 16, 2023 am 10:37 AM

The solution to the garbled mysql load data: 1. Find the SQL statement with garbled characters; 2. Modify the statement to "LOAD DATA LOCAL INFILE "employee.txt" INTO TABLE EMPLOYEE character set utf8;".

What are the differences between xdata and data What are the differences between xdata and data Dec 11, 2023 am 11:30 AM

The differences are: 1. xdata usually refers to independent variables, while data refers to the entire data set; 2. xdata is mainly used to establish data analysis models, while data is used for data analysis and statistics; 3. xdata is usually used for regression Analysis, variance analysis, predictive modeling, data can be analyzed using various statistical methods; 4. xdata usually requires data preprocessing, and data can contain complete original data.

More returns than sales: The Humane Ai Pin is becoming a commercial disaster More returns than sales: The Humane Ai Pin is becoming a commercial disaster Aug 08, 2024 pm 01:14 PM

Shortly after the launch of the Humane Ai Pin, scathing reviews revealed that the AI gadget was anything but ready for the market, as most of the originally advertised features either didn't work properly or were simply missing, the battery life was

Can't data in vue component be a function? Can't data in vue component be a function? Dec 19, 2022 pm 05:22 PM

No, data in the vue component must be a function. Components in Vue are used for reuse. In order to prevent data reuse, they are defined as functions. The data data in the vue component should be isolated from each other and not affect each other. Every time the component is reused, the data data should be copied once. Later, when the data data in the component is changed in a reused place, other data will be copied. If the data data of reused local components is not affected, you need to return an object as the status of the component through the data function.

See all articles