php - 文件获取内容(): stream does not support seeking PHP

标签 php file-get-contents

我正在尝试使用 file_get_contents() 仅从假名称生成器站点获取名称 (https://fakena.me/fake-name/),但是我收到以下警告:

file_get_contents() stream does not support seeking 

我不需要页面的全部内容。我只需要此站点中的名称部分:https://fakena.me/fake-name/ .


我的代码:

$name= file_get_contents('https://fakena.me/fake-name/', NULL, NULL, 849, 32);

它在本地主机上运行良好,仅在实时网站中显示错误。

最佳答案

您可以在 documentation 中阅读相关信息:

Seeking (offset) is not supported with remote files. Attempting to seek on non-local files may work with small offsets, but this is unpredictable because it works on the buffered stream.

您可以做的是在检索页面内容后使用 substr:

$part = substr($name, 849, 32);

关于php - 文件获取内容(): stream does not support seeking PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40816714/

相关文章:

php - 为什么要使用 Zend Framework 2 中的服务管理器?

php - 主键错误(自动增量int)在php中调用存储过程

php - 我可以在 MySQL 中存储图像吗

php - 通过 Twillion 将联系人分享到 iPhone

php - 从 file_get_contents() 值创建数组

php - Symfony2 bundle 与 PSR-0 兼容的第 3 方库之间有什么区别?

PHP file_get_contents/CURL 不返回整页

php - file_get_contents 没有缓存?

php - file_get_contents() "failed to open stream: Network is unreachable"有效链接错误

php - 忽略 file_get_contents HTTP 包装器中的错误?