当前位置: 代码迷 >> PHP >> 大神改版后的四六级总分如何用正则表达式获取(旧版的小弟我会获取)
  详细解决方案

大神改版后的四六级总分如何用正则表达式获取(旧版的小弟我会获取)

热度:77   发布时间:2016-04-28 19:21:11.0
请教各位大神改版后的四六级总分怎么用正则表达式获取(旧版的我会获取)
这是四六级网站
<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("&nbsp;","",$score);  
return array('school'=>$school,'name'=>$yourname,'cet'=>$cet,'score'=>$score);

其他的都能获取到  就总分那里获取不到
------解决方案--------------------
$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] => 赵阳