Tutorialsplane

Php add Image Height Width Regular Expression

function addImgHeightWidth($string='') { 
$pattern = "/(<img\s+).*?src=((\".*?\")|(\'.*?\')|([^\s]*)).*?>/is"; 
$replacement = "<img width='350' height='350' src=$2>";
$finalStr = preg_replace($pattern, $replacement, $string); return $string; }

The above function will add image height width in image tag. This can be used to convert images to amp Valid images.