From The Blog

Get the sources of img tags from html

21 October 2013, in PHPWordPress

/**
* get the sources of img tags from html input parameter
*/
function get_html_img_sources($html){
//$html = types_render_field( "gallery_image", array( "size" => "medium", "proportional" => "true",'output'=>'raw') );
if(empty($html))
return array();
$doc = new DOMDocument();
$doc->loadHTML($html);
$imageTags = $doc->getElementsByTagName('img');

$img_src_arr = array();
foreach($imageTags as $tag) {
$img_src_arr[] = get_site_url().'/'.substr( $tag->getAttribute('src'), strrpos( $tag->getAttribute('src'), '/wp-content' )+1 );
}
return $img_src_arr;
}



Post a Comment