How to extract img src, title and alt from html using php

preg_match_all match the regexp in all the $html string and output everything as
an array in $result. “i” option is used to make it case insensitive

preg_match_all('/<img[^>]+>/i',$html, $result);

print_r($result);

Get the metadata

$img = array();
foreach( $result as $img_tag)
{
preg_match_all('/(alt|title|src)=("[^"]*")/i',$img_tag, $img[$img_tag]);
}

print_r($img);

Here you go.

Posts Tagged regex

Archives by Month: