file_get_contents():流不支持查找PHP [英] file_get_contents(): stream does not support seeking PHP

查看:620
本文介绍了file_get_contents():流不支持查找PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use file_get_contents() to grab only Name from fake name generator site(https://fakena.me/fake-name/), however I'm getting the following warning:

file_get_contents() stream does not support seeking 

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


我的代码:

I dont need entire content of the page. I need only Name section in this site: https://fakena.me/fake-name/.


My code:

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

它在localhost中运行良好,仅在实时网站中显示错误.

Its working well in localhost, showing error only in live website.

推荐答案

您可以在

远程文件不支持搜索(偏移).试图 在非本地文件上搜索可能具有较小的偏移量,但这是 无法预测,因为它适用于缓冲流.

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:

What you can do is use substr after what you retrive the contents of the page:

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

这篇关于file_get_contents():流不支持查找PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆