Heim > Artikel > Backend-Entwicklung > 关于正则表达式的问题,非常感谢!
以下为抓取到的页面,想通过正则表达式函数取出里边的关于教师课表安排的信息,希望各位大侠给帮忙,谢谢。
HTTP/1.1 200 OK
Connection: close
Date: Thu, 07 May 2015 07:44:28 GMT
Server: YxlinkWAF
X-Powered-By: ASP.NET
X-AspNet-Version: 1.1.4322
Cache-Control: private
Content-Type: text/html; charset=gb2312
Content-Length: 11062
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
里面的信息很多,请给一个期望的结果数据格式
最好把原来的链接贴出来,然后告诉期望的格式
比如以上信息最终获取的结果是:可以取出其中的:星期一,线性代数B,1-17(3,4), 王黎峰, 电教楼205, 计科14(1);星期四,线性代数B,1-17(3,4),王黎峰,电教楼205,计科14(1)
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 "<pre class="brush:php;toolbar:false">";print_r($res);echo "";/*Array( [name] => 王峰 [info] => Array ( [星期一] => Array ( [0] => [1] => [2] => 线性代数B1-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] => 线性代数B1-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 = ";print_r($arr);echo "";