Forum Moderators: coopster

Message Too Old, No Replies

Problem with file()

         

ahmedtheking

7:55 pm on Jul 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've got a problem with file(), it seems to not be reading the file into an array line by line, but just the whole file!

Sekka

8:35 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



That is strange. What file are you reading?

ahmedtheking

8:52 pm on Jul 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's this:

The only way I resolved the issue was by changing the file so that instead of there being new lines, the file would be one line, but each line (previous line that is) is seperated by '___'

[edited by: jatar_k at 11:05 pm (utc) on July 3, 2006]
[edit reason] no urls thanks [/edit]

Sekka

10:38 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Try using this method,

$myPage = file_get_contents ("url");
$myArray = split ("\n", $myPage);

This will get the page as a complete string, like file () is doing for you at the moment, then splits each line to an array using the new line break.

That should work at least.

ahmedtheking

7:50 am on Jul 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll try that out, sorry about the urls. Any idea why file() may not work?

Sekka

8:27 am on Jul 4, 2006 (gmt 0)

10+ Year Member



Possibly because it's raw text and there's no normal file format? No idea. :(

ahmedtheking

8:33 am on Jul 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do you mean?

Sekka

11:28 am on Jul 4, 2006 (gmt 0)

10+ Year Member



I'm not sure to be honest. It was a wild guess. Ignore me. :)

coopster

4:27 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you using a Mac? Did you read the notes on the file() [php.net] manual page?


Note: If you are having problems with PHP not recognizing the line endings when reading files either on or created by a Macintosh computer, you might want to enable the auto_detect_line_endings run-time configuration option.

ahmedtheking

4:31 pm on Jul 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm using a mac, but the server is linux. It's all good now, recompiled PHP!