I'm tring to read in the text file found here: http://www1.m2.mediacat.ne.jp/binews/use/bia13.txt
It's a tab delimited list of shortwave radio broadcast schedules that I want to stuff into a MySQL database. I'm able to download it and get it into an array. A var_dump shows it's all there. However...
$schedule=file('schedule.txt');
foreach($schedule as $line)
{
echo $line.'<br>';
}
Only shows the last line of the file.
for ($i; $i<=count($schedule);$i++)
{
echo $schedule[$i];
}
generates an Apache 500 internal server error (premature end of script headers).
but, if I do this:
echo $schedule[0];
It properly displays that line.
So, I'm assuming somewhere in the array are some unprintable or control characters that are giving Apache fits.
I have done:
$bigstring=json_encode($schedule);
$schedule=$json_decode($bigstring);
that allows me to do a foreach on $schedule and it prints it out
and I have have tried in the foreach to:
echo utf8_decode($line).'<br>';
and that lets me run a foreach and it displays the lines but both these 'working' solutions strip out the tabs/spacing I need to break the lines into fields.
Any ideas on how I can either load this differently into an array that I can do a foreach on and parse it or is there a good way to show what control/character codes might be causing the crashes/hiccups?
Thanks
I might be missing something but in the for loop shouldn't you initialize $i to a value? The following worked for me to display the contents of the file:
$schedule = file("bia13.txt");
$count = count($schedule);
echo "<pre>";
for ($i = 0; $i < $count; $i++) {
echo $schedule[$i];
}
echo "</pre>";
My webhost gives me an Apache 500 error whenever PHP runs into a fatal error. That could possibly be where your error comes from.
I think there is nothing wrong in to code. It may be due to settings or trigger actions which are not supported by your Apache server config.
so you need to edit htaccess files.