<?php
/* PHP regular extraction of any attributes in the img tag in the image */
$str = '<center><img src="/uploads/images/" height="120" width="120"><br />PHP regular extraction or change any attribute in the image img tag</center>';
//1. Take the entire picture code
preg_match('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$str,$match);
echo $match[0];
//2. Take the width attribute
preg_match('/<img.+(width=\"?\d*\"?).+>/i',$str,$match);
echo $match[1];
//3. Take the height attribute
preg_match('/<img.+(height=\"?\d*\"?).+>/i',$str,$match);
echo $match[1];
//4. Take src
preg_match('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$str,$match);
echo $match[1];
//1. Replace src="/uploads/images/" with src="/uploads/uc/images/")
print preg_replace('/(<img.+src=\"?.+)(images\/)(.+\.(jpg|gif|bmp|bnp|png)\"?.+>)/i',"\${1}uc/images/\${3}",$str);
echo "<hr/>";
//2. Replace src="/uploads/images/" with src="/uploads/uc/images/", and save width and height
print preg_replace('/(<img).+(src=\"?.+)images\/(.+\.(jpg|gif|bmp|bnp|png)\"?).+>/i',"\${1} \${2}uc/images/\${3}>",$str);
?>