1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| private function classresult($xh,$pwd){ date_default_timezone_set("PRC"); $classList = "";
$cookie = $this->login($xh,$pwd); $view = $this->getViewJs($cookie,$xh);
if (!empty($view)) { $url = "http://jw.hzau.edu.cn/xskbcx.aspx?xh={$xh}"; $result = curl_request($url,'',$cookie); preg_match_all('/<table id="Table1"[\w\W]*?>([\w\W]*?)<\/table>/',$result,$out); $table = $out[0][0];
preg_match_all('/<td [\w\W]*?>([\w\W]*?)<\/td>/',$table,$out); $td = $out[1]; $length = count($td);
for ($i=0; $i < $length; $i++) { $td[$i] = str_replace("<br>", "", $td[$i]);
$reg = "/{(.*)}/"; if (!preg_match_all($reg, $td[$i], $matches)) { unset($td[$i]); } }
$td = array_values($td); $tdLength = count($td); for ($i=0; $i < $tdLength; $i++) { $td[$i] = iconv('GB2312','UTF-8',$td[$i]); }
function converttoTable($table){ $list = array( 'sun' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'mon' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'tues' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'wed' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'thur' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'fri' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ), 'sat' => array( '1,2' => '', '3,4' => '', '5,6' => '', '7,8' => '', '9,10' => '' ) ); $week = array("sun"=>"周日","mon"=>"周一","tues"=>"周二","wed"=>"周三","thur"=>"周四","fri"=>"周五","sat"=>"周六"); $order = array('1,2','3,4','5,6','7,8','9,10'); foreach ($table as $key => $value) { $class = $value; foreach ($week as $key => $weekDay) { $pos = strpos($class,$weekDay); if ($pos) { $weekArrayDay = $key; foreach ($order as $key => $orderClass) { $pos = strpos($class,$orderClass); if ($pos) { $weekArrayOrder = $orderClass; break; } } break; } } $list[$weekArrayDay][$weekArrayOrder] = $class; } return $list; } return converttoTable($td); }else{ return 0; } }
|