日期:2014-05-17  浏览次数:20438 次

php正则表达方式输出结果过滤
PHP code
<?php   
$url="http://117.36.53.122:9082/wfcx/query.do?actiontype=vioSurveil&hpzl=02&hphm=AP808P&tj=SYR&tj_val=%E5%8F%B1%E4%B8%BA%E5%9F%8E";
$s=file_get_contents($url);
preg_match_all('/<table width="100%"[^>]+>(.*)<\/td>
<\/tr>/isU',$s,$m);
for ($i=0; $i< count($m[0]); $i++) {
  echo "<table width=\"100%\" border=\"0\" class=\"mycar4\">".$m[1][$i]."\n";
}
?> 

查询输出得到结果
HTML code

<table width="100%" border="0" class="mycar4">

     <tr>

        <td bgcolor="#baeafe" class="font_biaoti" height="25" width="12%">号牌种类</td>

        <td>&nbsp;小型汽车</td>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">号牌号码</td>

        <td>&nbsp;ax098</td>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">中文品牌</td>

        <td>&nbsp;上海波罗</td>

    </tr>

    <tr>

        <td bgcolor="#baeafe" class="font_biaoti" height="25" width="12%">车辆型号</td>

        <td>&nbsp;SVW7144CLi</td>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">车辆类型</td>

        <td>&nbsp;轿车</td>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">车身颜色</td>

        <td>&nbsp;蓝</td>

    </tr>

    <tr>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">检验有效期止</td>

        <td>&nbsp;2013-01-31</td>

        <td bgcolor="#baeafe" class="font_biaoti" width="12%">强制报废期止</td>

        <td>&nbsp;2099-12-31</td>

        <td bgcolor="#baeafe" class="font_biaoti" height="25" width="12%">机动车状态</td>

        <td>&nbsp;违法未处理</td>

    </tr>

    <tr>

        <td bgcolor="#baeafe" height="25" class="font_biaoti" width="12%">机动车所有人</td>

        <td colspan="5">&nbsp;某某/td>

    </tr>

    
<table width="100%" border="0" class="mycar4">

    <tr bgcolor="#baeafe">

    <td height="25" align="center" class="font_biaoti"><b>号牌号码</b></td>

    <td align="center" class="font_biaoti"><b>号牌种类</b></td>

    <td align="center" class="font_biaoti"><b>违法时间</b></td>

    <td align="center" class="font_biaoti"><b>违法地点</b></td>

    <td align="center" class="font_biaoti"><b>违法行为</b></td>

    <td align="center" class="font_biaoti"><b>发现机关</b></td>

    <td align="center" class="font_biaoti"><b>信息来源</b></td>

    </tr>

    

    

    <TR style="cursor:hand">

    

        <td align="center" height="22">ax098</td>

        <td align="center">小型汽车</td>

        <td align="center">2012-05-15 13:48:12.0</td>

        <td align="center">建工路</t