php用正则表达式从html中截取表格内容,把第二个表格取出来并输出
<divclass="zx_info"><formid="cninfoform"name="cninfoform"action=“"method="post"onsubm...
<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> 展开
<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> 展开
1个回答
展开全部
跟 之前是一样的问题 对吗?
-----------------------------
<?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);
?>
-----------------------------
<?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);
?>
更多追问追答
追问
对,之前的代码放到这不灵了
追答
呵呵 是的, 主要是 里面 数量不一样
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |