Maison  >  Article  >  développement back-end  >  php正则表达式提取html标签的问题

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

PHP中文网
PHP中文网original
2017-03-22 15:47:313480parcourir

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>

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

回复讨论(解决方案)

$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程序

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn