doujiao2443 2013-08-01 15:03
浏览 53
已采纳

php数组中的.txt文件没有显示/ Apache 500错误

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

  • 写回答

2条回答 默认 最新

  • duanjing4623 2013-08-01 15:19
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)