php正则表达式提取图片地址 超链接 标题 实现代
  
  
   时间:2014-06-09 16:40来源: 作者: 点击:
   
   次
  
  
  正则表达式提取网址中的id,代码如下: preg_match( /http://t.sina.com.cn/(d+)/fans// , $html , $result );//正则表达式提取网址中的id echo $result [1]; PHP的正则表达式提取图片地址的代码,代码如下: $str = pstyle=p
  
  
   
    
     | 
       正则表达式提取网址中的id,代码如下: 
	
	- preg_match('/http://t.sina.com.cn/(d+)/fans//',$html,$result); //正则表达式提取网址中的id 
 
	- echo $result[1]; 
 
	 
 
PHP的正则表达式提取图片地址的代码,代码如下: 
	
	- $str='<p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_4.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_3.jpg" alt=""/></p><p style="padding: 0px; margin-top: 0px; margin-bottom: 0px; line-height: 200%;"><img border="0" src="upfiles/2009/07/1246430143_1.jpg" alt=""/></p>';  $pattern="/<[img|IMG].*?src=['|"](.*?(?:[.gif|.jpg]))['|"].*?[/]?>/";  preg_match_all($pattern,$str,$match);  print_r($match); 
 
	 
 
PHP正则表达式提取超链接及其标题,代码如下: 
	
	- $str = '<a id="top8" href="http://list.MP3.baidu.com/song/A.htm?top8" class="p14" target="_top">歌曲列表</a><br><a target="_blank" id="bp" href="http://list.mp3.baidu.com/list/bangping.html" class="p14">中文金曲榜</a><br><td nowrap="nowrap">• <a id="top19" href="qingyinyue.html?top19" class="p14" target="_top">轻音乐</a></td>'; 
 
	- 利用正则表达式是最简单的,其它的办法,偶米去想。。。 
 
	- $pat = '/<a(.*?)href="(.*?)"(.*?)>(.*?)</a>/i'; 
 
	- preg_match_all($pat, $str, $m); 
 
	 
 
输出方法:print_r($m[2]);print_r($m[4]); 
      
      (责任编辑:admin) | 
    
   
   
  
  
  
  
   ------分隔线----------------------------