PHP头条
热点:

php正则表达式提取图片地址 超链接 标题 实现代码


文章介绍了利用php正则表达式提取图片地址 超链接 标题 实现代码,有需要的朋友可参考一下。

正则表达式提取网址中的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">&#8226;&nbsp;<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]);

www.phpzy.comtrue/php/21394.htmlTechArticlephp正则表达式提取图片地址 超链接 标题 实现代码 文章介绍了利用php正则表达式提取图片地址 超链接 标题 实现代码,有需要的朋友可参考一下。 正则表达式提取网址中的id 代码如下...

相关文章

PHP之友评论

今天推荐