Reputation: 79
I have an image Tag like
<img src="abc" height="20" width="50" />
How can I extract only the source from it in php?
Upvotes: 0
Views: 251
Reputation: 18917
You could use SimpleXML very quickly here:
$sxe = new SimpleXMLElement('<img src="abc" height="20" width="50" />');
$src = (string) $sxe['src'];
Upvotes: 2
Reputation: 11839
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;
?>
Upvotes: -1