Friday, 13 September 2013

Explode() is giving server error, page can't load

Explode() is giving server error, page can't load

<?php
$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
print_r ($theData);
fclose($fh)
?>
This is my current code, which has successfully read my file and printed
the data to the screen. However now when I try to explode the data I just
get a sever error and the page doesn't load at all, the only error message
I get it "page may be down for maintenance or configured incorrectly" and
I don't understand why it isn't working.
I am trying to put
$my_array = explode("/n", $theData);
after the data has been read, and before it is printed, but every time I
add it the page gives up, but when I take it out the page loads again
fine. I need to be able to put in a foreach loop to explode the data and
print it out one line at a time (it's an email directory) but I don't
understand why it's not working.
$myFile = "file.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
$assoc_array = array()
$my_array = explode("\n", $theData);
foreach($my_array as $line)
{
$tmp = explode(" ", $line);
$assoc_array[$tmp[0]] = $tmp[1];
}
fclose($fh)
$mail = $assoc_array;
I have tried this code, which I found while doing the original research
for how to read from .txt file to array, but it still throws up the server
error problem.
Could someone explain where I'm going wrong?

No comments:

Post a Comment