我正在尝试使用 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/