0

我正在使用 Simple DOM HTML 解析器库解析一些 HTML,并且在我的 foreach 语句中,我试图将一些值添加到以下格式的数组中。但是,循环挂起,chrome 每次都会收到“Aw Snap”消息。怎么了?

数组格式:

Array
(
    [wccca_number] => xxx
    [call_name] => xxx
    [address] => xxx
    [county] => xxx
    [station] => xxx
    [department] => xxx
    [units] => xxx
    [call_created] => xxx
)
Array
(
    [wccca_number] => xxx
    [call_name] => xxx
    [address] => xxx
    [county] => xxx
    [station] => xxx
    [department] => xxx
    [units] => xxx
    [call_created] => xxx
)

代码:

Class WCCCA_HTMLParser {

    private $html;
    private $wa_county_header;
    private $cla_county_header;
    private $active_calls;
    private $wa_calls_array;
    private $cla_calls_array;

    public function __construct()  {  

        $this->html                  = file_get_html('http://www.wccca.com/PITSv2/');
        $this->wa_county_header      = $this->html->find('div[id=wccca-incidents]');  
        $this->cla_county_header     = $this->html->find('div[id=ccom-incidents]');  
        $this->active_calls          = array(); 
        $this->wa_calls_array        = array();
        $this->cla_calls_array       = array();

        $this->find_wa_county_calls();

        print_r($this->wa_calls_array);
    }  

    public function find_wa_county_calls () {

        foreach ($this->wa_county_header as $call_header) {

            foreach ($call_header->find('div[id^=list_]') as $node) {

                $call_name = $node->children(0)->children(1)->children(1)->children(0); // Path to the call text

                $address = $node->children(1)->children(1)->children(0); // Path to the address text

                $wccca_number = $node->children(1)->children(1)->children(1)->children(0); // Path to the WCCCA Number text

                $call_created = $node->children(2)->children(1)->children(0)->children(0); // Path to the call created text

                $department = $node->children(3)->children(0)->children(0)->children(0); // Path to the department text

                $station = $node->children(3)->children(0)->children(0)->children(1); // Path to the station text

                $units_node = $node->children(3)->children(0)->children(0)->children(2); // Path to the units text
                $units_array = array();
                foreach ($units_node->find('span') as $unit) {
                    array_push($units_array, $unit->innertext);
                }
                $units = implode(', ', $units_array);

                $county = 'W'; // Set the county character

                $this->wa_calls_array['wccca_number'] = $wccca_number;
                $this->wa_calls_array['call_name'] = $call_name;
                $this->wa_calls_array['address'] = $address;
                $this->wa_calls_array['county'] = $county;
                $this->wa_calls_array['station'] = $station;
                $this->wa_calls_array['department'] = $department;
                $this->wa_calls_array['units'] = $units;
                $this->wa_calls_array['call_created'] = $call_created;
            }
        }
    }
}
4

0 回答 0