Пример #1
0
 protected function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(1), 1 => array(2), 2 => array(3), 3 => array(4), 4 => array(5));
     $arr = array();
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = '';
         foreach ($dArr as $dRow) {
             $element = $xpath->query('/html/body/div[2]/div[2]/article/div/div/p[' . $dRow . ']');
             foreach ($element as $e) {
                 $dayMenuExploded = explode(PHP_EOL, $e->nodeValue);
                 $foodArray = array();
                 foreach ($dayMenuExploded as $foods) {
                     $foods = parent::cleanStr($foods);
                     if (!empty($foods)) {
                         $foodArray[] = preg_replace('/([\\t0-9, ]+$)/', '', $foods);
                     }
                 }
                 $dayMenu = implode(' / ', $foodArray);
             }
         }
         $weekDay = parent::weekNumToText($dId);
         $arr[$weekDay] = parent::fixSpaces(preg_replace('/[0-9, ]+$/', '', $dayMenu));
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
Пример #2
0
 /**
  * @param string $html HTML document
  * @return boolean|array
  */
 public function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(2, 3, 4));
     $arr = array();
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = array();
         foreach ($dArr as $dRow) {
             $element = $xpath->query('/html/body/div[2]/div/div/div/div/div[' . $dRow . ']/div[1]');
             foreach ($element as $e) {
                 $dish = ucfirst(strtolower(parent::cleanStr(utf8_decode(parent::fixSpaces(trim($e->nodeValue))))));
                 $dish = preg_replace('/\\([a-z, ]+\\)/e', 'strtoupper("$0")', $dish);
                 $dayMenu[] = $dish;
             }
         }
         $weekDay = parent::today();
         $arr[$weekDay] = implode(' / ', $dayMenu);
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
Пример #3
0
 protected function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $element = $xpath->query('//*[@id="menu"]/div[*]');
     $arr = array();
     $i = 0;
     $lunchListInHTML = $doc->saveHTML($element->item(0));
     $lunchListInArray = explode('<hr class="mini">', $lunchListInHTML);
     foreach ($lunchListInArray as $lunchPerDay) {
         $foods = preg_replace('/^[a-zA-Z]{2} [0-9]{1,2}\\.[0-9]{1,2}\\./', '', trim(strip_tags($lunchPerDay)));
         $foodsArray = explode(PHP_EOL, $foods);
         $dayMenu = array();
         foreach ($foodsArray as $food) {
             $dayMenu[] = preg_replace('/ ([a-zA-Z,]+)$/', ' (${1})', parent::cleanStr($food));
         }
         $weekDay = parent::weekNumToText($i);
         $arr[$weekDay] = parent::fixSpaces(implode(' / ', $dayMenu));
         $i++;
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
Пример #4
0
 /**
  * @param string $html HTML document
  * @return boolean|array
  */
 public function HTMLtoLunchArray($html)
 {
     $xml = simplexml_load_string($html);
     foreach ($xml->channel as $channel) {
         foreach ($channel->item as $item) {
             $data = $item->description;
             $doc = new DOMDocument();
             @$doc->loadHTML($data);
             $xpath = new DOMXpath($doc);
             $elements = $xpath->query('//p');
             $foodArrs = array();
             $i = -1;
             if (!is_null($elements)) {
                 foreach ($elements as $element) {
                     $nodes = $element->childNodes;
                     foreach ($nodes as $node) {
                         if (preg_match('/Maanantai|Tiistai|Keskiviikko|Torstai|Perjantai/i', $node->nodeValue)) {
                             $i++;
                         } elseif (preg_match('/tervetuloa|P.*iv.*n j.*lkiruoka|pienet muutokset/i', $node->nodeValue)) {
                             continue;
                         } else {
                             if ($i > -1 && strlen($node->nodeValue) > 3) {
                                 $weekDay = parent::weekNumToText($i);
                                 $foodArrs[$weekDay][] = utf8_decode(trim($node->nodeValue));
                             }
                         }
                     }
                 }
             }
             $arr = array();
             foreach ($foodArrs as $weekDay => $foodArr) {
                 $arr[$weekDay] = parent::cleanStr(str_replace('*, ', '', parent::fixSpaces(implode(' / ', $foodArr))));
             }
             continue 2;
         }
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }