dongyu8664 2013-08-26 10:38
浏览 37
已采纳

从文本和html标签中检测并提取图像URL

How can i detect if there is some image html tag inside a text and extract just the url of the image ?

Eg.

Extract this url :

http://
www.someurl.com/somefileprocessor.php/12345/somedir/somesubdir/someniceimage.j
pg

from this tag (this tag can be inside another bunch of text and/or html)

<img title="Some nice title" border="0"
hspace="0" alt="some useful hint" src="http://
www.someurl.com/somefileprocessor.php/12345/somedir/somesubdir/someniceimage.j
pg" width="629" height="464" />

Thank's in advance Ângelo

  • 写回答

3条回答 默认 最新

  • dpr77335 2013-08-26 11:11
    关注

    A quick attempt at an <img/> tag specific regex:

    preg_match_all('/<img[^>]*?\s+src\s*=\s*"([^"]+)"[^>]*?>/i', $str, $matches);
    

    Example

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部