下面是经过一部分处理的源代码
<?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("'<table[^>]*?>'si","",$exam); $exam = preg_replace("'<tr[^>]*?>'si","",$exam); $exam = preg_replace("'<td[^>]*?>'si","",$exam); $exam = str_replace("</tr>","{tr}",$exam); $exam = str_replace("</td>","{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 [课程] => 流体力学 [日期] => 2014-11-0600:00:00.0 [时间] => 14:00-16:00 [班级] => 土木122 [考场] => Ⅲ-209 [任课教师] => 巩妮娜 [] => )
我想应该是第二种 作为一个数组变量插入到模板中 谢谢大神
版主,可以问个小问题吗?[日期] => 2014-11-0600:00:00.0这个数据在页面上是没有00:00:00.0这些的,能去掉吗?
$s = '2014-11-0600:00:00.0';echo date('Y-m-d', strtotime($s));echo substr($s, 0, 10);
谢谢版主,如此敬业,感激万分,此贴终结!