关于PHP正则匹配取出数据的有关问题
时间:2021-07-01 10:21:17
帮助过:16人阅读
关于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
人气教程排行