PHP正規マッチングによるデータ抽出の問題について
以下は途中まで加工したソースコードです
<?php<br />$exam = curl_init("http://exam.hhit.edu.cn/fgquery.do?status=lowquery&tsid=2012120348");<br />curl_setopt($exam, CURLOPT_RETURNTRANSFER, true); // 获取数据返回<br />curl_setopt($exam, CURLOPT_BINARYTRANSFER, true); // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回<br />$exam=curl_exec($exam);<br /> $exam = preg_replace("'<table[^>]*?>'si","",$exam); <br /> $exam = preg_replace("'<tr[^>]*?>'si","",$exam); <br /> $exam = preg_replace("'<td[^>]*?>'si","",$exam); <br /> $exam = str_replace("</tr>","{tr}",$exam); <br /> $exam = str_replace("</td>","{td}",$exam); <br /> //去掉 HTML 标记 <br /> $exam = preg_replace("'<[/!]*?[^<>]*?>'si","",$exam); <br /> //去掉空白字符 <br /> $exam = preg_replace("'([rn])[s]+'","",$exam);<br /> $exam = preg_replace('/ /',"",$exam); <br /> $exam = str_replace(" ","",$exam); <br /> $exam = str_replace(" ","",$exam); <br /> $exam = explode('{tr}', $exam);<br /> array_pop($exam); <br /> print_r($exam);<br />?>
[19] => <br />编号{td}<br />课程{td}<br />日期{td}<br />时间{td}<br />班级{td}<br />考场{td}<br />任课教师{td}<br /><br />[20] => <br />1{td}<br />流体力学{td}<br />2014-11-0600:00:00.0<br />{td}<br />14:00-16:00{td}<br />土木122{td}<br />Ⅲ-209{td}<br />巩妮娜{td}
print_r(array_map(null, explode('{td}', $exam[19]), explode('{td}', $exam[20])));<br />
Array<br />(<br /> [0] => Array<br /> (<br /> [0] => 编号<br /> [1] => 1<br /> )<br /><br /> [1] => Array<br /> (<br /> [0] => 课程<br /> [1] => 流体力学<br /> )<br /><br /> [2] => Array<br /> (<br /> [0] => 日期<br /> [1] => 2014-11-0600:00:00.0<br /> )<br /><br /> [3] => Array<br /> (<br /> [0] => 时间<br /> [1] => 14:00-16:00<br /> )<br /><br /> [4] => Array<br /> (<br /> [0] => 班级<br /> [1] => 土木122<br /> )<br /><br /> [5] => Array<br /> (<br /> [0] => 考场<br /> [1] => Ⅲ-209<br /> )<br /><br /> [6] => Array<br /> (<br /> [0] => 任课教师<br /> [1] => 巩妮娜<br /> )<br /><br /> [7] => Array<br /> (<br /> [0] => <br /> [1] => <br /> )<br /><br />)
print_r(array_combine(explode('{td}', $exam[19]), explode('{td}', $exam[20])));
Array<br>(<br> [Number] => 1<div class="clear"> </div>