function process($db, $file) { $content = file_get_contents($file); $txt = strip_tags($content); $txt = iconv('EUC-KR', 'UTF-8', $content); $tokens = preg_split('/\\s+/', $txt); $billArr = []; $bill = false; $title = ""; foreach ($tokens as $line) { if (startsWith($line, 'href="javascript:GoDetail(')) { if ($bill) { // Do something with bill echo $bill->toString() . "\n"; storeContent($db, $bill); } $id = parseBillId($line); $bill = new Bill($id); continue; } if (!$bill) { continue; } if (isDate($line)) { if (!$bill->proposed) { $bill->proposed = $line; } else { if (!$bill->processed) { $bill->processed = $line; } } continue; } if (startsWith($line, 'title="')) { $title .= $line; continue; } if ($title != "") { $title .= $line; } if (strpos($line, ')">') !== false) { $arr = explode('"', $title); if (count($arr) > 2) { $bill->titleHTML = $arr[1]; } $title = ""; } switch ($line) { case '부결': case '철회': case '대안반영폐기': case '수정가결': case '원안가결': $bill->result = $line; break; case '위원장': case '의원': case '정부': $bill->proposedby = $line; break; case '공포': case '본회의의결': } } // Add the last if there. if ($bill) { // Do something with bill echo $bill->toString() . "\n"; storeContent($db, $bill); } }