Jump to content

file() vs. file_get_contents()


AV1611

Recommended Posts

I'm having a hard time understanding the difference between file() and file_get_contents()

 

I usually use this when parsing a text file to a data base when the text file is on a website.

 

sometimes one works, sometimes the other works when you do something like this:

 

$lines=file('http://mysite.com/file.txt');

foreach($lines as $line_num => line){

...etc...

 

sometimes I have to do file_get_contents() instead...

 

Can someone explain?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/56878-file-vs-file_get_contents/
Share on other sites

Here is the problem I don't understand on my new webserver I built:

 

I did this and it works:

 

$lines=file_get_contents('http://site.com/file.txt');

$lines=nl2br($lines);

$lines=explode("<br />",$lines);

foreach($lines as $line_num => $line){

...

 

Isn't that the same as this?  It produces no output...???

 

$lines=file('http://site/file.txt)

foreach....

 

??????????????????????????????

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.