0
    $drivetracker = simplexml_load_file('geot_5980.xml');
    $currentDrive = "init";
    $save = 0;
    $drive = 0;
    $break = 0;
    $display = 0;
    $changeDrive = 0;
    $endhalf = 0;
    $data = array();
    $driveArr = array();

    foreach ($drivetracker->plays->qtr as $qtr):
        foreach ($qtr->play as $myplay):
        $hasball = (string)$myplay['hasball'];
            $play = (string)$myplay['spot'];
            $down = (string)$myplay['down'];
        $togo = (string)$myplay['togo'];
        $type = (string)$myplay['type'];
        $text = (string)$myplay['text'];

            $hasball = mb_convert_encoding($hasball, 'UTF-8');
            $play = mb_convert_encoding($play, 'UTF-8');
            $down = mb_convert_encoding($down, 'UTF-8');
            $togo = mb_convert_encoding($togo, 'UTF-8');
            $type = mb_convert_encoding($type, 'UTF-8');
            $text = mb_convert_encoding($text, 'UTF-8');

        if ($save == 0 && strpos($text, 'start') !== FALSE){
        $save = 1;
        $break = 1;
        } else if ($save == 1 && strpos($text, 'start') !== FALSE) {
        $break = 1;
        } else if ($save == 1 && strpos($text, 'Start') !== FALSE) {
        $break = 1;
        } else if ($save == 1 && strpos($text, 'ball') !== FALSE) {
        $break = 1;
        } else if ($save == 1 && strpos($text, 'Timeout') !== FALSE) {
        $break = 1;
        } else if ($save == 1 && strpos($text, 'and') !== FALSE) {
        $break = 1;
        }

        //ignore all plays when save is false
        if($save == 0){$break = 1;}

        if($break == 0){
        //drive check
        if (strpos($currentDrive, 'init') !== FALSE){        
            $currentDrive = $hasball;
            $drive += 1;
        } else if ($currentDrive != $hasball){  
            $currentDrive = $hasball;
            $drive += 1;
            $display = 1;
        } else if (strpos($text, 'End of half') !== FALSE) { // end of half or game so new drive
            $endhalf = 1;
        }

                if($drive == $driveid){
                    array_push($data, array("text" => $text,                
                    "spot" => $play,
                    "ball" => $hasball,
                    "togo" => $togo,
                    "type" => $type,
                    "drive"=> $drive)
               );
                }

        if($endhalf == 1) {
            $drive += 1;
        }
        }

        //resetter after each iteration
        $break = 0;
        $display = 0;
        $endhalf = 0;
        endforeach;
    endforeach;
    print_r($data);
    echo json_encode($data);

print_r($data) は、

Array ( [0] => Array ( [text] => Godhigh, R. rush for 2 yards to the GT27 (Canty, W). [spot] => GT25 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [1] => Array ( [text] => Days, S. rush for 5 yards to the GT32 (Woodruff, J;Brown, Ky). [spot] => GT27 [ball] => GT [togo] => 8 [type] => R [drive] => 7 ) [2] => Array ( [text] => Sims, D. rush for 6 yards to the GT38, 1ST DOWN GT (Anunike, K;Sarmiento, S). [spot] => GT32 [ball] => GT [togo] => 3 [type] => R [drive] => 7 ) [3] => Array ( [text] => Godhigh, R. rush for 18 yards to the DU44, 1ST DOWN GT (Cockrell, R). [spot] => GT38 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [4] => Array ( [text] => Lee, V. pass complete to Greene, J. for 5 yards to the DU39 (Foster, T). [spot] => DU44 [ball] => GT [togo] => 10 [type] => P [drive] => 7 ) [5] => Array ( [text] => Laskey, Z. rush for 9 yards to the DU35 (Sink, N). [spot] => DU44 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [6] => Array ( [text] => Laskey, Z. rush for 5 yards to the DU30, 1ST DOWN GT (Canty, W;France, C). [spot] => DU35 [ball] => GT [togo] => 1 [type] => R [drive] => 7 ) [7] => Array ( [text] => Laskey, Z. rush for 4 yards to the DU26 (Sink, N). [spot] => DU30 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [8] => Array ( [text] => Lee, V. rush for 3 yards to the DU23 (Brown, Ky). [spot] => DU26 [ball] => GT [togo] => 6 [type] => R [drive] => 7 ) [9] => Array ( [text] => Laskey, Z. rush for 5 yards to the DU18, 1ST DOWN GT (Canty, W). [spot] => DU23 [ball] => GT [togo] => 3 [type] => R [drive] => 7 ) [10] => Array ( [text] => Smith, O. rush for 8 yards to the DU10 (France, C). [spot] => DU18 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [11] => Array ( [text] => Lee, V. rush for 4 yards to the DU6, 1ST DOWN GT (France, C). [spot] => DU10 [ball] => GT [togo] => 2 [type] => R [drive] => 7 ) [12] => Array ( [text] => Laskey, Z. rush for 3 yards to the DU3 (Helton, D;Woodruff, J). [spot] => DU06 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [13] => Array ( [text] => Laskey, Z. rush for no gain to the DU3 (Woodruff, J;Brown, Ky). [spot] => DU03 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [14] => Array ( [text] => Smith, O. rush for 1 yard to the DU2 (France, C). [spot] => DU03 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [15] => Array ( [text] => Lee, V. rush for 2 yards to the DU0, TOUCHDOWN, clock 04:34. [spot] => DU02 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [16] => Array ( [text] => Tanner, C. kick attempt good. [spot] => DU03 [ball] => GT [togo] => 0 [type] => X [drive] => 7 ) [17] => Array ( [text] => Tanner, C. kickoff 51 yards to the DU14, Butler, L return 16 yards to the DU30 (Noble, D.). [spot] => GT35 [ball] => GT [togo] => 0 [type] => K [drive] => 7 ) )

json_encode($data) は空白になります...

xml 情報で構成されるこの php 配列を json 経由でエンコードできない理由を知っている人はいますか?

4

0 に答える 0