使用php从远程动态创建的文本文件中获取数据

时间:2021-07-23 15:40:42

I'm trying to get (with PHP) data from a remote text file. The URL of the file is website.com/page.php?info=someinfo. So it's not a .txt file, I don't know if that matters. The whole contents of the page are text, however. When looking at the source, there is no HTML, only plain text.

我正试图从远程文本文件中获取(使用PHP)数据。该文件的URL是website.com/page.php?info=someinfo。所以它不是.txt文件,我不知道这是否重要。但是,页面的全部内容都是文本。查看源代码时,没有HTML,只有纯文本。

I've been trying to get the data using fopen() and fread(), and file_get_contents. However, both methods give me a screen filled with "404, object not found" errors, placed all over the place. Does anyone know how to solve this?

我一直在尝试使用fopen()和fread()以及file_get_contents来获取数据。但是,这两种方法都给了我一个屏幕,里面装满了“404,找不到对象”的错误。有谁知道如何解决这个问题?

Thanks,

谢谢,

1 个解决方案

#1


0  

"website.com/page.php?info=someinfo" is not a text file, this is an HTML stream.

“website.com/page.php?info=someinfo”不是文本文件,这是一个HTML流。

If you want to sniff the html content resulting from the query to "website.com/page.php?info=someinfo" then you have to use file_get_contents only, not fread nor fopen.

如果你想将查询产生的html内容嗅到“website.com/page.php?info=someinfo”,那么你必须只使用file_get_contents,而不是fread或fopen。

#1


0  

"website.com/page.php?info=someinfo" is not a text file, this is an HTML stream.

“website.com/page.php?info=someinfo”不是文本文件,这是一个HTML流。

If you want to sniff the html content resulting from the query to "website.com/page.php?info=someinfo" then you have to use file_get_contents only, not fread nor fopen.

如果你想将查询产生的html内容嗅到“website.com/page.php?info=someinfo”,那么你必须只使用file_get_contents,而不是fread或fopen。