Exemplo n.º 1
0
 /**
  * HtmlDom test
  *
  * @return void
  */
 public function testBasics()
 {
     $html = new HtmlDom('<div id="hello">Hello</div><div id="world">World</div>');
     $result = $html->find('div', 1)->innertext;
     $this->assertSame('World', $result);
 }
Exemplo n.º 2
0
 /**
  * Manually import from import.txt using content from input textarea on
  * http://de.wikipedia.org/w/index.php?title=Liste_der_St%C3%A4dte_in_%C3%96sterreich&action=edit&section=4
  *
  * @return array cities or FALSE on failure
  */
 protected function _importAt()
 {
     $url = 'http://de.wikipedia.org/w/index.php?title=Liste_der_St%C3%A4dte_in_%C3%96sterreich&action=edit&section=4';
     $content = $this->_getFromUrl($url);
     $HtmlDom = new HtmlDom($content);
     $res = $HtmlDom->find('textarea', 0)->innertext;
     if (empty($res)) {
         trigger_error('URL not accessable');
         return false;
     }
     $res = substr($res, strpos($res, '(F 2007)') + 8);
     $res = substr($res, 0, strpos($res, '|}'));
     $array = [];
     $res = explode('|-', $res);
     foreach ($res as $key => $val) {
         if (empty($val)) {
             continue;
         }
         $tmp = explode('||', $val);
         if (count($tmp) < 5) {
             continue;
         }
         # bug in wikipedia bbcode markup
         if (count($tmp) === 6) {
             $tmp[6] = $tmp[5];
         }
         $t = [];
         $t['city'] = $this->_parse($tmp[0]);
         $t['county'] = $this->_parse($tmp[1]);
         $t['state'] = $this->_parse($tmp[2]);
         $t['citizens'] = (int) str_replace('.', '', $this->_parse($tmp[6]));
         $t['country'] = 'AT';
         $t['country_id'] = $this->Countries->getIdByIso('AT');
         if ($t['county'] === '<sup>2</sup>') {
             $t['county'] = $t['city'];
         }
         $array[] = $t;
     }
     $counties = [];
     foreach ($array as $city) {
         if (!isset($counties[$city['county']])) {
             $counties[$city['county']] = 1;
         } else {
             $counties[$city['county']]++;
         }
     }
     foreach ($array as $key => $city) {
         $county = $city['county'];
         $array[$key]['single_city'] = !empty($counties[$county]) && $counties[$county] > 1 ? 0 : 1;
     }
     return $array;
 }