Because there is a project press release system, the database content field is stored in the original image of the path (and of course, there are other text content, the content of the illustrations, save the picture path), but the front desk want to use thumbnails, pondering 1 hours, get the following results to solve the problem (take the IMG tag will be, Take another label any property will naturally also be:
Copy Code code as follows:
<?php
/* Regular take picture of any attribute in the IMG tag * *
$word = ' <p height= "align=" Cenetr ">111 22</p> <div style= "float:left;" > Chinese </div> ';
Take the whole picture code
Preg_match ('/</s*img/s+[^>]*?src/s*=/s* (/' |/') (. *?) 1[^>]*?//?/s*>/i ', $word, $matches);
echo $matches [0];//results:
$word = ' <p height= "align=" Cenetr ">111 22</p> <div style=" float:left; > Chinese </div> ';
Take width
Preg_match ('//i ', $word, $matches);
echo $matches [1];
Take height
Preg_match ('//i ', $word, $matches);
echo $matches [1];
Take SRC
Preg_match ('//i ', $word, $matches);
echo $matches [1];
/* Regular replacement Remove or change any attribute in the image img Tag ***************************************************************/
$str = ' <p height= "align=" Cenetr ">111 22</p> <div style=" float:left; > Chinese </div>
<p height= "align=" Cenetr ">31313 224344</p> <div style= "float:left;" >1212121</div> ';
Change the src attribute (where the original src= "Http://files.jb51.net/upload/images/bbb.jpg" is changed to src=) http://files.jb51.net/upload/_thumbs/ Images/bbb.jpg ")
Print Preg_replace ('/()/I ', "/${1}_thumbs/images//${3}", $STR);
/* Change 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", and discard width and height
(for example, you want to display thumbnails in the foreground, but the database stores the path of the original image.) Why do you want to abandon the width of the high? You thumbnails Ah! or the original image of the width of the height, how will???)
*/
Print Preg_replace ('/(/i ', "/${1}/${2}_thumbs/images//${3}>", $STR);
?>