關於PHP正則匹配取出資料的問題
下面是經過一部分處理的原始碼
$exam = curl_init("http://exam.hhit.edu.cn/fgquery.do?status=lowquery&tsid=2012120348");
curl_setopt($exam, CURLOPT_RETURNTRANSFER, true); // 擷取資料返回
curl_setopt($exam, CURLOPT_BINARYTRANSFER, true); // 在啟用 CURLOPT_RETURNTRANSFER 時候將擷取資料返回
$exam=curl_exec($exam);
$exam = preg_replace("']*?>'si","",$exam);
$exam = preg_replace("']*?>'si","",$exam);
$exam = preg_replace("']*?>'si","",$exam);
$exam = str_replace("","{tr}",$exam);
$exam = str_replace("","{td}",$exam);
//去掉 HTML 標籤
$exam = preg_replace("'<[/!]*?[^<>]*?>'si","",$exam);
//去掉空白字元
$exam = preg_replace("'([rn])[s]+'","",$exam);
$exam = preg_replace('/ /',"",$exam);
$exam = str_replace(" ","",$exam);
$exam = str_replace(" ","",$exam);
$exam = explode('{tr}', $exam);
array_pop($exam);
print_r($exam);
?>
我想要的是取出下面這一段資料放到數組裡,不知道該怎麼寫了,第一次接觸正則感覺看不懂,謝謝各位大神們!
[19] =>
編號{td}
課程{td}
日期{td}
時間{td}
班級{td}
考場{td}
任課教師{td}
[20] =>
1{td}
流體力學{td}
2014-11-0600:00:00.0
{td}
14:00-16:00{td}
土木122{td}
Ⅲ-209{td}
鞏妮娜{td}
------解決思路----------------------
你是要這樣的
print_r(array_map(null, explode('{td}', $exam[19]), explode('{td}', $exam[20])));
Array
(
[0] => Array
(
[0] => 編號
[1] => 1
)
[1] => Array
(
[0] => 課程
[1] => 流體力學
)
[2] => Array
(
[0] => 日期
[1] => 2014-11-0600:00:00.0
)
[3] => Array
(
[0] => 時間
[1] => 14:00-16:00
)
[4] => Array
(
[0] => 班級
[1] => 土木122
)
[5] => Array
(
[0] => 考場
[1] => Ⅲ-209
)
[6] => Array
(
[0] => 任課教師
[1] => 鞏妮娜
)
[7] => Array
(
[0] =>
[1] =>
)
)
還是這樣的
print_r(array_combine(explode('{td}', $exam[19]), explode('{td}', $exam[20])));
Array
(
[編號] => 1