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

PHP中文网
Release: 2023-02-28 16:52:02
Original
3477 people have browsed it

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>
Copy after login

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

回复讨论(解决方案)

$pattern = "/<td Height=\"30\">([\s\S]*)<\/td>/"; 
preg_match_all($pattern, $str, $matches); 
var_dump($matches);
Copy after login
Copy after login

测试可以通过

$pattern = "/<td Height=\"30\">([\s\S]*)<\/td>/"; 
preg_match_all($pattern, $str, $matches); 
var_dump($matches);
Copy after login
Copy after login

测试可以通过
规则改下

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

preg_match_all("/<td\s+Height=\"30\">(.*)<\/td>/iUs", $str, $output);print_r($output);
Copy after login

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

相关文章:

提取html标签的php代码示例

通过php提取HTML标签

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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!