php正则表达式提取html标签的问题

PHP中文网
发布: 2023-02-28 16:52:02
原创
3478 人浏览过

php正则表达式提取html标签的问题

<tr>    
<td  Height="30"> 
·<a class="index_libiao" href="http://www.zh818.com/html/2014/033/7155319.aspx" 
title="3月14日上海钢材市场价格汇总" target="_blank">            	
<font color="#0000FF"> 3月14日上海钢材市场价格汇总</font>        
</a>
</td>    
<td align="Right">
<span class="biaotiriqi"> 3月14日</span>
</td>  
</tr>  
<tr>    
<td  Height="30"> 
·<a class="index_libiao" href="http://www.zh818.com/html/2014/033/7155318.aspx" 
title="3月14日北京钢材市场价格汇总" target="_blank">            	
<font color="#0000FF"> 3月14日北京钢材市场价格汇总</font>        
</a>
</td>    
<td align="Right">
<span class="biaotiriqi"> 3月14日</span>
</td>  
</tr>  
<tr>    
<td  Height="30"> 
·<a class="index_libiao" href="http://www.zh818.com/html/2014/033/7155317.aspx" 
title="3月14日天津钢材市场价格汇总" target="_blank">            	
<font color="#0000FF"> 3月14日天津钢材市场价格汇总</font>        
</a>
</td>    
<td align="Right">
<span class="biaotiriqi"> 3月14日</span>
</td>  
</tr>  
<tr>    
<td  Height="30"> 
·<a class="index_libiao" href="http://www.zh818.com/html/2014/033/7155316.aspx" 
title="3月14日重庆钢材市场价格汇总" target="_blank">            	
<font color="#0000FF"> 3月14日重庆钢材市场价格汇总</font>        
</a>
</td>    
<td align="Right">
<span class="biaotiriqi"> 3月14日</span>
</td>  
</tr>  
<tr>    
<td  Height="30"> 
·<a class="index_libiao" href="http://www.zh818.com/html/2014/033/7155315.aspx" 
title="3月14日广州钢材市场价格汇总" target="_blank">            	
<font color="#0000FF"> 3月14日广州钢材市场价格汇总</font>        
</a>
</td>
登录后复制

我想获取所有×××的标签中间的内容,应该怎么写正则表达式呢

回复讨论(解决方案)

$pattern = "/<td Height=\"30\">([\s\S]*)<\/td>/"; 
preg_match_all($pattern, $str, $matches); 
var_dump($matches);
登录后复制
登录后复制

测试可以通过

$pattern = "/<td Height=\"30\">([\s\S]*)<\/td>/"; 
preg_match_all($pattern, $str, $matches); 
var_dump($matches);
登录后复制
登录后复制

测试可以通过
规则改下

$pattern = "/<td  Height=\"30\">([\s\S]*?)<\/td>/"

preg_match_all("/<td\s+Height=\"30\">(.*)<\/td>/iUs", $str, $output);print_r($output);
登录后复制

以上就是php正则表达式提取html标签的问题的内容,更多相关内容请关注PHP中文网(www.php.cn)!

相关文章:

提取html标签的php代码示例

通过php提取HTML标签

php 正则表达式提取图片url程序

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!