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 |
// Return the Course table string Private function classresult ($ xh, $ pwd ){ Date_default_timezone_set ("PRC"); // set the time zone $ ClassList = ""; // declare Course table Variables $ Cookie = $ this-> login ($ xh, $ pwd ); $ View = $ this-> getViewJs ($ cookie, $ xh); // verify that the password is correct // If the password is correct If (! Empty ($ view )){ $ Url = "http://jw.hzau.edu.cn/xskbcx.aspx? Xh = {$ xh }"; $ Result = curl_request ($ url, '', $ cookie); // saved cookies Preg_match_all ('/<table id = "Table1" [\ w \ W] *?> ([\ W \ W] *?) <\/Table>/', $ result, $ out ); $ Table = $ out [0] [0]; // obtain the entire course table Preg_match_all ('/<td [\ w \ W] *?> ([\ W \ W] *?) <\/Td>/', $ table, $ out ); $ Td = $ out [1]; $ Length = count ($ td ); // Obtain the course list 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); // re-index the course list Array $ TdLength = count ($ td ); For ($ I = 0; $ I <$ tdLength; $ I ++ ){ $ Td [$ I] = iconv ('gb2312', 'utf-8', $ td [$ I]); } // Convert the course list to an array 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" => "Sunday", "mon" => "Monday", "tues" => "Tuesday ", "wed" => "Wednesday", "thur" => "ththursday", "fri" => "Friday", "sat" => "Saturday "); $ 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; // obtain the first-dimensional key in the list Array Foreach ($ order as $ key => $ orderClass ){ $ Pos = strpos ($ class, $ orderClass ); If ($ pos ){ $ WeekArrayOrder = $ orderClass; // The number of times the course is obtained Break; } } Break; } } $ List [$ weekArrayDay] [$ weekArrayOrder] = $ class; } Return $ list; } // Call a function Return converttoTable ($ td ); } Else { Return 0; } } |