예제 #1
0
 /**
  * Parsing the course html file.
  *
  * @param string $file
  * @param string $academic
  * @return array
  */
 protected function parsingFile($file, $academic)
 {
     $content = file_get_contents($file);
     // 確認是正確的學期,已防匯入舊資料
     if (!mb_strpos($content, $academic)) {
         return [];
     } else {
         if (mb_strpos($content, '教師未定')) {
             $this->comment("{$file} 此檔案含有「教師未定」課程,該檔案之所有課程已略過");
             return [];
         }
     }
     $html = $this->htmldom->str_get_html(str_ireplace('<font color=red>', '', $content));
     // 取得系所
     $department = $html->find('h1', 0)->plaintext;
     $department = trim(substr($department, strpos($department, ':') + 1));
     // 判斷是否為通通識課程
     $isGeneral = '通識教育中心' === $department;
     // 取得課程資料
     $courses = [];
     $pos = 0 + ($isGeneral ? 1 : 0);
     $lessons = $html->find('table tr');
     array_shift($lessons);
     foreach ($lessons as $lesson) {
         $t = explode(PHP_EOL, trim($lesson->children($pos + 3)->plaintext));
         $courses[] = ['dimension' => $isGeneral ? trim($lesson->children($pos)->plaintext) : null, 'code' => trim($lesson->children($pos + 1)->plaintext), 'name' => trim($t[0]), 'name_en' => trim($t[1]), 'professor' => str_replace(' ', ',', trim($lesson->children($pos + 4)->plaintext))];
     }
     return compact('department', 'isGeneral', 'courses');
 }
예제 #2
0
 /**
  * @param string $str
  * @param bool $lowercase
  * @return object Dom
  */
 public function domFromString($str, $lowercase = true)
 {
     return parent::str_get_html($str, $lowercase);
 }