gpt4 book ai didi

php - fseek() : stream does not support seeking

转载 作者:行者123 更新时间:2023-12-03 03:17:27 24 4
gpt4 key购买 nike

读取.txt文件并获取文本文件的最后一行,我使用的函数在下面注释

function read_last_line (){

$line = '';

$f = fopen('localpath\data.txt', 'r');
$cursor = -1;

fseek($f, $cursor, SEEK_END);
$char = fgetc($f);

/**
* Trim trailing newline chars of the file
*/
while ($char === "\n" || $char === "\r") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}

/**
* Read until the start of the file or first newline char
*/
while ($char !== false && $char !== "\n" && $char !== "\r") {
/**
* Prepend the new char
*/
$line = $char . $line;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
echo $line;
}

在执行上述代码时,我得到fseek(): Stream does not supportlooking,需要一个解决方案来解决该问题。

最佳答案

不支持所有形式的查找,并且在某些情况下会失败。

更多详细信息请查看文档 https://www.php.net/manual/en/function.fseek.php

关于php - fseek() : stream does not support seeking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59891417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com