PHP Regular extract any attribute modifications in the IMG tag
/*php extract any attribute from the IMG tag in the image */
$str? =? '
PHP is extracting or changing any of the attributes in the image img Tag ';
1, take the entire picture code
Preg_match ('/<\s*img\s+[^>]*?src\s*=\s* (\ ' |\ ') (. *?) \\1[^>]*?\/?\s*>/i ', $str, $match);
echo $match [0];
2. Take width
Preg_match ('//i ', $str, $match);
echo $match [1];
3. Take height
Preg_match ('//i ', $str, $match);
echo $match [1];
4. Take SRC
Preg_match ('//i ', $str, $match);
echo $match [1];
/*php Replace any attribute in the image img Tag */
1. Replace src= "/uploads/images/20100516000.jpg" with src= "/uploads/uc/images/20100516000.jpg")
Print?preg_replace ('/()/I ', "\${1}uc/images/\${3}", $STR);
Echo? " ";
2. Replace src= "/uploads/images/20100516000.jpg" with src= "/uploads/uc/images/20100516000.jpg" and omit width and height
Print?preg_replace ('/(/I ', "\${1}?\${2}uc/images/\${3}>", $str);