当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > fseek() 函数

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 fseek() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 534 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The fseek() function seeks in an open file.
fseek()函数的作用是:查找文件中指针所指向的内容。

This function moves the file pointer from its current position to a new position, forward or backward, specified by the number of bytes.
整个函数将文件指针从当前位置向前或向后移动移动到一个新的位置。

This function returns 0 on success, or -1 on failure. Seeking past EOF will not generate an error.
函数执行成功返回0;执行失败返回-1。如果搜索到文件末尾[EOF]将产生一个错误。

Syntax
语法

fseek(file,offset,whence)

Parameter参数 Description描述
file Required. Specifies the open file to seek in
必要参数。指定需要执行搜索的文件对象
offset Required. Specifies the new position (measured in bytes from the beginning of the file)
必要参数。指定一个新的位置(设置从文件开头的第几个字节处进行搜索)
whence Optional. (added in PHP 4). Possible values:
可选参数(PHP 4以上版本支持),可用值如下:
  • SEEK_SET - Set position equal to offset. Default
    SEEK_SET – 默认值。搜索位置与offset值相等
  • SEEK_CUR - Set position to current location plus offset
    SEEK_CUR – 搜索的位置等于offset值加上当前地址的值
  • SEEK_END - Set position to EOF plus offset (to move to a position before EOF, the offset must be a negative value)
    SEEK_END -搜索的位置等于offset值加上文件末尾[EOF]的值(在移动到文件末尾之前,offset的值必须是负数)


Tips and Notes
提示

Tip: Find the current position by using ftell()!
提示:可以使用ftell()函数查找当前所处的位置。


Example
案例

<?php
$file = fopen("test.txt","r");
// read first line
fgets($file);
// move back to beginning of file
fseek($file,0);
?>

评论 (0) All

登陆 | 还没注册?