Try like this
$pattern = '/<img.+src=(.)(.*)\1[^>]*>/iU';
$callback_fn = 'process';
$string = 'this is dummy string <img src="imageone.jpg" alt="" /> this is another sentesnces <img src="imagetwo.jpg" /> this is third one';
$content = preg_replace_callback($pattern, $callback_fn, $string);
function process($matches)
{
return " <a href='http://mywebsite.com/".$matches[2]."'> <font color ='black' >View Image</font> </a>";
}
echo $content;
Also instead of <font>
tag, use <span>
because <font>
is deprecated.