Created
February 5, 2014 06:26
-
-
Save ihsanberahim/8818316 to your computer and use it in GitHub Desktop.
extract image source attribute from html string in Drupal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: ihsanberahim | |
* Author Url: http://blog.powergeng.com | |
* Author Facebook: http://facebook.com/ihsanberahim | |
* | |
* i found it from stackoverflow | |
*/ | |
function content2src($html){ | |
$doc = new DOMDocument(); | |
libxml_use_internal_errors(true); | |
$doc->loadHTML( $html ); | |
$xpath = new DOMXPath($doc); | |
$imgs = $xpath->query("//img"); | |
for ($i=0; $i < $imgs->length; $i++) { | |
$img = $imgs->item($i); | |
$src = $img->getAttribute("src"); | |
} | |
return $src; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment