开发者

Extract src from image Tag

I have an image Tag like

<img src="abc" height="20" width="50" />

How can I extract 开发者_开发问答only the source from it in php?


You could use SimpleXML very quickly here:

$sxe = new SimpleXMLElement('<img src="abc" height="20" width="50" />');
$src = (string) $sxe['src'];


The best way would be to use regular expressions.

<?php
$tag='<img src="abc" height="20" width="50" />';
$extracted=preg_replace('/<img [^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/','\\1',$tag);
echo $extracted;
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜