Because there is a project news release system, the path of the original image is stored in the database content field (of course there are other text contents. When the illustration is in the content, the image path is stored), but the front desk wants to use thumbnails, and I have been thinking about it for more than an hour. , the following results are obtained, which can solve the problem (you can take the img tag, and you can take any attribute of other tags naturally):
/*Regularly select any attribute in the image img tag*/
$word = '
111 22
Chinese
';
//Get the entire image code
preg_match('/]*?src/s *=/s*(/'|/")(.*?)//1[^>]*?//?/s*>/i',$word,$matches);
echo $matches[0];//Result:
$word = '
111 22
Chinese
';
//Get width
preg_match('/
/i',$word,$matches);
echo $matches[1];
//Get height
preg_match('//i',$word,$matches);
echo $matches[1];
//Get src
preg_match('//i ',$word,$matches);
echo $matches[1];
/*Regular replacement removes or changes any attribute in the image img tag****************** *************************************************** **/
$str = '111 22
Chinese
31313 224344
1212121
';
//Change the src attribute (here the original src="http://files.jb51.net/upload/images /bbb.jpg" changed to src="http://files.jb51.net/upload/_thumbs/Images/bbb.jpg")
print preg_replace('/()/i',"/${1}_thumbs/Images//${3 }",$str);
/*Change the src attribute,
Change the original src="http://files.jb51.net/upload/images/bbb.jpg" here to src="http://files.jb51.net/upload/_thumbs/Images/bbb.jpg", and discard the width and height
(for example, you want to display thumbnails in the foreground, but the original image is stored in the database path. Why should you abandon the width and height?? Your thumbnail! What will happen if it is still the width and height of the original image???)
*/
print preg_replace('/(/i',"/${1} /${2}_thumbs/Images/ /${3}>",$str);
?>