關於PHP正則匹配取出資料的有關問題

來源:互聯網
上載者:User
關於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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.