Because there is a project news publishing system, the path of the source image is stored in the database content field (of course there are other text content. When illustrations are in the content, the image path is saved ), however, if you want to use a thumbnail on the front-end for more than one hour, you can solve the problem by having a project news publishing system, the source image path is stored in the content field of the database (of course there are other text content, while the image path is stored in the illustration), but the front-end wants to use thumbnails, after an hour, we can get the following results to solve the problem (the img tag will be used, and any attribute of other tags will naturally be used ):
The code is as follows:
/* Obtain any attribute in the img Mark of the image using regular expressions */
$ Word ='
111 22
Chinese
';
// Retrieve the entire image code
Preg_match ('/] *? Src/s * =/s * (/'| /")(.*?) // 1 [^>] *? //? /S *>/I ', $ word, $ matches );
Echo $ matches [0]; // result:
$ Word ='
111 22
Chinese
';
// Obtain the width
Preg_match ('// I', $ word, $ matches );
Echo $ matches [1];
// Take the height
Preg_match ('// I', $ word, $ matches );
Echo $ matches [1];
// Obtain src
Preg_match ('// I', $ word, $ matches );
Echo $ matches [1];
/* Remove or change any attribute in the img Mark of the image through regular expression replacement *************************** ************************************/
$ Str ='
111 22
Chinese
31313 224344
1212121
';
// Change the src property (here change the original src = "http://files.bitsCN.com/upload/images/bbb.jpg" to src = "http://files.bitsCN.com/upload/_thumbs/Images/bbb.jpg ")
Print preg_replace ('/()/I', "/$ {1} _ thumbs/Images // $ {3}", $ str );
/* Change the src attribute,
Here we change the original src = "http://files.bitsCN.com/upload/images/bbb.jpg" to src = "http://files.bitsCN.com/upload/_thumbs/Images/bbb.jpg" and discard the width and height
(For example, if you want to display thumbnails on the front-end, but the path of the source image is stored in the database. Why should we discard the width and height ?? You have a thumbnail! Or what will happen to the width and height of the source image ???)
*/
Print preg_replace ('/(/I', "/$ {1}/$ {2} _ thumbs/Images // $ {3}>", $ str );
?>