Jump to content

preg_match


drisate

Recommended Posts

hey guys. I am trying to replace the size of every images posted to max it at 460px but the script works only for the first image. All the others use the same value so if theres 6 images in the poste it will be 6 time the same image.

 

$regex = '/(<img.*?src="(.*?)".*?>)/';

preg_match($regex,$sb_message_txt,$match);

$picinfo = getimagesize($match[2]);

$picinfo[0] = ($picinfo[0] > 460)? 460 : $picinfo[0];

$replacement =  '<img src="'.$match[2].'" width="'.$picinfo[0].'" border="0" alt="" />';

$sb_message_txt=preg_replace($regex, $replacement, $sb_message_txt);

Link to comment
Share on other sites

I tryed

 

preg_match_all($regex,$sb_message_txt,$match);

$picinfo = getimagesize($match[2]);

$picinfo[0] = ($picinfo[0] > 460)? 460 : $picinfo[0];

$replacement =  '<img src="'.$match[2].'" width="'.$picinfo[0].'" border="0" alt="" />';

$sb_message_txt=preg_match_all($regex, $replacement, $sb_message_txt);

 

But getimagesize returns an error because $match[2] is null

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.