duanjiu3486 2016-03-18 07:47
浏览 45

数组在PHP中消失

Here is my code:

public function pgn_oku() {
    $n=-1;
    $x=-1;  
    $detay="";
    $hamle="";
    $file = fopen("D:\satranc\bielcki\kaleli_roklu_vezirli.pgn","r");

    while(! feof($file)) {
        $n=$n+1;
        $detay[$n]= fgets($file);
        $detay[$n]=trim($detay[$n]);
        if (empty($detay[$n])) {
            $x=$x+1;
            $hamle1[$x]= fgets($file);
            $hamle = explode(' ', $hamle1[$x]);
            print_r(array_values($hamle))."<br>";
        } else  {
            echo $detay[$n]."<br>";
            echo $n."<br>";
        }
    }

    print_r(array_values($detay))."<br><br>";
    echo "<br><br>";
    print_r(array_values($hamle))."<br>";
    echo "<br><br>";

    fclose($file);
}

And this is what I get as a result:

[Event "?"]
0
[Site "?"]
1
[Date "????.??.??"]
2
[Round "?"]
3
[White "?"]
4
[Black "?"]
5
[Result "*"]
6
Array ( [0] => 1.b4 [1] => c5 [2] => 2.bxc5 [3] => d6 [4] => 3.cxd6 [5] => Qxd6 [6] => 4.e3 [7] => Nf6 [8] => 5.c4 [9] => b5 [10] => 6.cxb5 [11] => e5 [12] => 7.b6 [13] => Be7 [14] => 8.bxa7 [15] => O-O [16] => 9.axb8=Q [17] => Bd7 [18] => 10.Qbb3 [19] => Rab8 [20] => 11.Qbc2 [21] => Rfd8 [22] => 12.Qe2 [23] => Rdc8 [24] => 13.Qcd3 [25] => Qe6 [26] => 14.Qf3 [27] => Qd5 [28] => 15.Qfxd5 [29] => Nxd5 [30] => 16.Qxd5 [31] => Rxc1+ [32] => 17.Ke2 [33] => Rbxb1 [34] => 18.Qxd7 [35] => Rxa1 [36] => 19.Nf3 [37] => Rxa2 [38] => 20.Qxe7 [39] => Rcc2 [40] => 21.h4 [41] => Rcb2 [42] => 22.h5 [43] => Rb8 [44] => 23.h6 [45] => Rba8 [46] => 24.Rh5 [47] => R2a7 [48] => 25.Qxe5 [49] => * ) Array ( [0] => ) Array ( [0] => [Event "?"] [1] => [Site "?"] [2] => [Date "????.??.??"] [3] => [Round "?"] [4] => [White "?"] [5] => [Black "?"] [6] => [Result "*"] [7] => [8] => )

Array ( [0] => ) 

The question is that the array $hamle is printed above but not below. I played around with a STATIC declaration but to no avail. Any help will be much appreciated.

NOTE: I am using the CodeIgniter framework.

The file that I am reading is:

[Event "?"] [Site "?"] [Date "????.??.??"] [Round "?"] [White "?"] [Black "?"] [Result "*"] 1.b4 c5 2.bxc5 d6 3.cxd6 Qxd6 4.e3 Nf6 5.c4 b5 6.cxb5 e5 7.b6 Be7 8.bxa7 O-O 9.axb8=Q Bd7 10.Qbb3 Rab8 11.Qbc2 Rfd8 12.Qe2 Rdc8 13.Qcd3 Qe6 14.Qf3 Qd5 15.Qfxd5 Nxd5 16.Qxd5 Rxc1+ 17.Ke2 Rbxb1 18.Qxd7 Rxa1 19.Nf3 Rxa2 20.Qxe7 Rcc2 21.h4 Rcb2 22.h5 Rb8 23.h6 Rba8 24.Rh5 R2a7 25.Qxe5 *
  • 写回答

1条回答 默认 最新

  • duanji1043 2016-03-23 11:07
    关注

    I found the answer as the following=> The code works it goes all the way to the end of the file to be read and at the last moment reads the final line which doesn't appear in copy and paste ( it is just a char I suppose) a break as follows does the trick=>

     $hamle = explode(' ', $hamle1[$x]);
        $GLOBALS['hamleg'] = $hamle;
    
             break;
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP