时间:2021-07-01 10:21:17 帮助过:30人阅读
include 'simple_html_dom.php';//这个你可以在网上下载一个
$dom=new simple_html_dom();
//要将内容转为 utf-8 才能处理
$dom->load($content);
$names=$dom->find('select[id=js]');
$res=array();
$res['name']=$names[0]->find('option[selected=selected]')[0]->text();
$tabletr=$dom->find('table[id=Table6] tr');
foreach($tabletr as $k=>$tr){
foreach($tr->find('td') as $k1=>$td){
if($k1!==0){
$info[$k][$k1]=$td->text();
}
}
}
//优化数据
foreach($info as $k=>$v){
if($k==1){
unset($info[1]);
}
if(count($v)==8){
unset($v[1]);
}
$info[$k]=array_values($v);
}
$week=$info[0];
unset($info[0]);
//组织数据
foreach($info as $v){
foreach($v as $k=>$v){
$tmp[$week[$k]][]=$v;
}
}
$res['info']=$tmp;
echo "";";
print_r($res);
echo "
/*
Array
(
[name] => 王峰
[info] => Array
(
[星期一] => Array
(
[0] =>
[1] =>
[2] => 线性代数B
1-17(3,4)
王黎峰
电教楼205
计科14(1)
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[星期二] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[星期三] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[星期四] => Array
(
[0] =>
[1] =>
[2] => 线性代数B
1-17(3,4)
王黎峰
电教楼205
计科14(1)
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[星期五] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
)
[星期六] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
[星期日] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
)
*/
//根据你自己的需求来处理课程信息
$txt = <<线性代数B
1-17(3,4)
王黎峰
电教楼205
计科14(1)
EOF;
$arr=explode(PHP_EOL,$txt);
echo "";";
print_r($arr);
echo "