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); //保存的cookies 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); // echo $pos; if ($pos) { $weekArrayDay = $key; //获取list数组中的第一维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; } }
$pos = strpos($class, $orderClass); if ($pos) { $weekArrayOrder = $orderClass; //获取该课程是第几节 break; } } break; } } $list[$weekArrayDay][$weekArrayOrder] = $class; } return $list; //return $pos; } $kc = converttoTable($td); //二维转一位 $i = 1; foreach ($kc as $key => $val) { foreach ($val as $value) { //echo $value; $yiwei[$i] = $value; $i++; } } //按json格式输出 function response($code, $data = array()) { $result = array('code' => $code, 'data' => $data); echo json_encode($result); exit;