简体   繁体   English

如何从文本文件url中读取内容

[英]How to read the contents from a text file url

Im having difficulty getting the contents of text file when Im trying to get the contents of that text file from a url. 我试图从url获取文本文件的内容时,无法获取文本文件的内容。

Say my text file url is http://example.com/files/text.txt . 说我的文本文件网址是http://example.com/files/text.txt

Whenever I try using file_get_contents(' http://example.com/files/text.txt '), it returns the actual source html code of that url. 每当我尝试使用file_get_contents(' http://example.com/files/text.txt ')时,它都会返回该URL的实际源HTML代码。 Is there a way to just read whats actually written in the text file itself? 有没有一种方法可以读取文本文件本身实际写的内容? I do know that to do what im trying to is is very easy with just using the file path, however the files im trying to get sit on another server. 我确实知道,仅使用文件路径即可轻松完成我想做的事情,但是我试图将文件放在另一台服务器上。 Any help with this? 有什么帮助吗? Thanks 谢谢

If you have access to said server you could use fopen function, however that requires fopen to be enabled cross domain via php.ini. 如果您可以访问上述服务器,则可以使用fopen函数,但是这要求通过php.ini跨域启用fopen。 Also in your regards it could be the headers are returning as html as opposed to plain text. 同样在您看来,标题可能会以html而不是纯文本形式返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM