drisate Posted December 17, 2008 Share Posted December 17, 2008 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 https://forums.phpfreaks.com/topic/137309-preg_match/ Share on other sites More sharing options...
genericnumber1 Posted December 17, 2008 Share Posted December 17, 2008 try using preg_match_all() instead of preg_match() Link to comment https://forums.phpfreaks.com/topic/137309-preg_match/#findComment-717438 Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 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 https://forums.phpfreaks.com/topic/137309-preg_match/#findComment-717444 Share on other sites More sharing options...
.josh Posted December 17, 2008 Share Posted December 17, 2008 I'm closing this thread as your other one is the exact same as this one, and you seem to be hovering around inside the other one. Please do not make multiple posts asking the same thing. Link to comment https://forums.phpfreaks.com/topic/137309-preg_match/#findComment-717457 Share on other sites More sharing options...
Recommended Posts