PHP Tutorial Regular fetch img tags alt src width heigh property
<?php
/* Regular take picture of any attribute in the IMG tag
$word = ' <p height= "align=" Cenetr ">111 22</p> <img src="/upload/images/aaa.jpg "width=" "/><div style=" float:left; > Chinese </div> ';
Take the whole picture code
Preg_match ('/<img [ ^<]*) src= "? (. [^< "]*"? (. [^<|/]*)/?>/is ', $word, $matches);
echo $matches [0];//results: <img src= "/upload/images/aaa.jpg" width= ">"
$word = ' <p height= ' align= "Cenetr" >111 22</p> <img height= "src="/upload/images/aaa.jpg "width=" "Style=><div style=" float:left; > Chinese </div> ';
Take width
Preg_match ('/<img.+ (width= "? d*"?). +>/i ', $word, $matches);
echo $matches [1];
Take height
Preg_match ('/<img.+ (height= "? d*"?). +>/i ', $word, $matches);
echo $matches [1];
Take SRC
Preg_match ('/<img.+src= "? +. (jpg|gif|bmp|bnp|png)) "? +>/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> <img height= "src="/upload/images/aaa.jpg Style=><div style= "Float:left;" > Chinese </div><p height= align= "Cenetr" >31313 224344</p> <img src= "/upload/images/bbb.jpg" height= "width=100" Style=><div style= "float:left;" >1212121</div> ';
Change the src attribute (where the original src= "/upload/images/bbb.jpg" is changed to Src= "/upload/_thumbs/images/bbb.jpg")
Print preg_replace ('/<img.+src= '? +) (images/) (. +.) ( Jpg|gif|bmp|bnp|png) "? +>)/I ', "${1}_thumbs/images/${3}", $STR);
/* Change the SRC attribute,
to change the original src= "/upload/images/bbb.jpg" to Src= "/upload/_thumbs/images/bbb.jpg" and discard the width and height
( For example, you want to display thumbnails in the foreground, but the database tutorial 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 ('/(<img). + (src= "? +) images/(. +.) ( Jpg|gif|bmp|bnp|png). +>/i ', "${1} ${2}_thumbs/images/${3}>", $STR);