php用正则表达式从html中截取表格内容,把第二个表格取出来并输出
发布网友
发布时间:2022-04-19 04:42
我来回答
共1个回答
热心网友
时间:2022-04-19 06:11
跟 之前是一样的问题 对吗?
-----------------------------
<?php
$content = '<div class="zx_info">
<form id="cninfoform" name="cninfoform" action=“" method="post" onsubmit="">
<input type="hidden" id="sc" name="sc" value="stock"/>
<input type="hidden" id="map" name="map" value=""/>
<table border="0" cellspacing="3" cellpadding="0">
<tr>
<td style="padding-right:10px" ></td>
<td valign="middle" >
<label>
<input id="stockID_" name="stockID_" type="text" onFocus="this.select()"
onClick="if(this.value==\'简称/拼音\')this.value=\'\'"
onMouseOver="this.focus()"
title="代码/简称/拼音"
style="WIDTH: 100px"
value=\'简称/拼音\'
autocomplete="off"
maxlength="6" />
</label>
</td>
<td>
<label>
<input type="submit" name="button" id="button" value="选择" class="input2" onClick="return true;"/>
</label>
</td>
</tr>
</table></form></div>
<div class="clear2">
<!-- 左边列表开始-->
<div class="zx_left">
<div class="zx_right_title">
<p>流通</p>
</div>
<div class="clear">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="10%" class="zx_data">截止时间</td>
<td width="42%" class="zx_data3">名称</td>
<td width="18%" class="zx_data3">数量</td>
<td width="15%" class="zx_data3">比例</td>
<td width="15%" class="zx_data3">性质</td>
</tr>
<tr>
<td rowspan="10" class="zx_data">20101231</td>
<td class="zx_data3">1.王维航</td>
<td class="zx_data3">53,810,630</td>
<td class="zx_data3">10.658</td>
<td class="zx_data3">流通</td>
</tr>
<tr>
<td class="zx_data3">2.苏纲</td>
<td class="zx_data3">53,255,463</td>
<td class="zx_data3">10.548</td>
<td class="zx_data3">流通</td>
</tr>
<tr>
<td class="zx_data3">8.杨成寿</td>
<td class="zx_data3">7,200,000</td>
<td class="zx_data3">1.426</td>
<td class="zx_data3">中通</td>
</tr>
<tr>
<td class="zx_data3">9.荆涛</td>
<td class="zx_data3">7,012,547</td>
<td class="zx_data3">1.389</td>
<td class="zx_data3">中通</td>
</tr>
</table>';
$content =explode('<tr>',$content);
$arr = array();
for($i=3;$i<count($content);$i++){
preg_match_all('/<td class="zx_data3">(.*)<\/td>/iU',$content[$i],$match);
$ma = explode('.',$match[1][0]);
array_shift($ma);
$match[1][0] = implode('.',$ma);
$arr[] = $match[1];
}
print_r($arr);
?>