请教各位大神改版后的四六级总分怎么用正则表达式获取(旧版的我会获取)

php中文网
发布: 2016-06-23 13:58:20
原创
1256人浏览过

这是四六级网站

<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">	<tr>		<th>姓名:</th>		<td>赵阳</td>	</tr>	<tr>		<th>学校:</th>		<td>长春中医药大学</td>	</tr>	<tr>		<th>考试类别:</th>		<td>英语四级</td>	</tr>	<tr>		<th>准考证号:</th>		<td>220090132112529</td>	</tr>	<tr>		<th>考试时间:</th>		<td>2013年12月</td>	</tr>	<tr>		<th valign="top">总分:</th>		<td valign="top" class="fontBold">        <span class="colorRed">					0		        </span>		        	<br /><span class="color666">听力:</span>							000			            <br /><span class="color666">阅读:</span>						000						            <br /><span class="color666">写作与翻译:</span>						000					</td>	</tr></table>
登录后复制

这是我的代码
$a = curl_exec($ch);			$match="#<td>(.*)</td>#";			//$match="#<span>(.*)</span>#";preg_match_all($match,$a,$b);$yourname= $b[1][0];$school= $b[1][1];$cet= $b[1][2];$c= $b[1][5];//分数$score=strip_tags($c);$score=str_replace(" ","",$score);  		return array('school'=>$school,'name'=>$yourname,'cet'=>$cet,'score'=>$score);
登录后复制

其他的都能获取到  就总分那里获取不到

简篇AI排版
简篇AI排版

AI排版工具,上传图文素材,秒出专业效果!

简篇AI排版 554
查看详情 简篇AI排版

回复讨论(解决方案)

$a =<<< TXT<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">    <tr>        <th>姓名:</th>        <td>赵阳</td>    </tr>    <tr>        <th>学校:</th>        <td>长春中医药大学</td>    </tr>    <tr>        <th>考试类别:</th>        <td>英语四级</td>    </tr>    <tr>        <th>准考证号:</th>        <td>220090132112529</td>    </tr>    <tr>        <th>考试时间:</th>        <td>2013年12月</td>    </tr>    <tr>        <th valign="top">总分:</th>        <td valign="top" class="fontBold">        <span class="colorRed">                     0                 </span>                     <br /><span class="color666">听力:</span>                             000                         <br /><span class="color666">阅读:</span>                         000                                      <br /><span class="color666">写作与翻译:</span>                         000                     </td>    </tr></table>TXT;$match="#<t[hd].*?>(.*?)</t[hd]>#is";preg_match_all($match,$a,$b);$b[1][11] = preg_replace('/\s/', '', strip_tags($b[1][11]));print_r($b[1]);
登录后复制
Array
(
    [0] => 姓名:
    [1] => 赵阳
    [2] => 学校:
    [3] => 长春中医药大学
    [4] => 考试类别:
    [5] => 英语四级
    [6] => 准考证号:
    [7] => 220090132112529
    [8] => 考试时间:
    [9] => 2013年12月
    [10] => 总分:
    [11] => 0听力:000阅读:000写作与翻译:000
)

$a =<<< TXT<table border="0" align="center" cellpadding="0" cellspacing="6" class="cetTable">    <tr>        <th>姓名:</th>        <td>赵阳</td>    </tr>    <tr>        <th>学校:</th>        <td>长春中医药大学</td>    </tr>    <tr>        <th>考试类别:</th>        <td>英语四级</td>    </tr>    <tr>        <th>准考证号:</th>        <td>220090132112529</td>    </tr>    <tr>        <th>考试时间:</th>        <td>2013年12月</td>    </tr>    <tr>        <th valign="top">总分:</th>        <td valign="top" class="fontBold">        <span class="colorRed">                     0                 </span>                     <br /><span class="color666">听力:</span>                             000                         <br /><span class="color666">阅读:</span>                         000                                      <br /><span class="color666">写作与翻译:</span>                         000                     </td>    </tr></table>TXT;$match="#<t[hd].*?>(.*?)</t[hd]>#is";preg_match_all($match,$a,$b);$b[1][11] = preg_replace('/\s/', '', strip_tags($b[1][11]));print_r($b[1]);
登录后复制
Array
(
    [0] => 姓名:
    [1] => 赵阳
    [2] => 学校:
    [3] => 长春中医药大学
    [4] => 考试类别:
    [5] => 英语四级
    [6] => 准考证号:
    [7] => 220090132112529
    [8] => 考试时间:
    [9] => 2013年12月
    [10] => 总分:
    [11] => 0听力:000阅读:000写作与翻译:000
)


但$a里的内容应该是变化的啊

内容是变化的,格式是固定的
否则就无所谓“采集”了

内容是变化的,格式是固定的
否则就无所谓“采集”了


现在有个问题最后一行?>报错
我把你这个
$match="#(.*?)[hd]>#is";
转义了还是报错
相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号