drisate Posted December 17, 2008 Share Posted December 17, 2008 Hi guys ia m having a hard time making this script work $sb_message_txt = $fmessage->message; $sb_message_txt = stripslashes(smile::smileReplace($sb_message_txt,0, $sbConfig['disemoticons'])); $sb_message_txt = str_replace("\n","<br />",$sb_message_txt); preg_match('/(<img.*?src="(.*?)".*?>)/',$sb_message_txt,$match); $picinfo = getimagesize($match[2]); $picinfo[0] = ($picinfo[0] > 430)? 430 : $picinfo[0]; $replacement = 'img src="'.$match[2].'" width="'.$picinfo[0].'" border="0" alt="" /'; $sb_message_txt = preg_replace($match[1], $replacement, $sb_message_txt); I am trying to resize every images bigger then 430 px but i get this error Warning: preg_replace() [function.preg-replace]: Empty regular expression in view.php on line 439 Line 439 is $sb_message_txt = preg_replace($match[1], $replacement, $sb_message_txt); Quote Link to comment Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 $match[1] will not be formatted as a regex, try this. $regex = '/(<img.*?src="(.*?)".*?>)/'; preg_match($regex,$sb_message_txt,$match); $picinfo = getimagesize($match[2]); $picinfo[0] = ($picinfo[0] > 430)? 430 : $picinfo[0]; $replacement = 'img src="'.$match[2].'" width="'.$picinfo[0].'" border="0" alt="" /'; $sb_message_txt = preg_replace($regex, $replacement, $sb_message_txt); Quote Link to comment Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 hmm it works but for some reason every images of the messages are replaces by the value of the first image img src="http:// img201.imageshack.us /img201/5206/ skellgriffot8.png" width="430" border="0" alt="" / img src="http:// img201.imageshack.us /img201/5206/ skellgriffot8.png" width="430" border="0" alt="" / img src="http:// img201.imageshack.us /img201/5206/ skellgriffot8.png" width="430" border="0" alt="" / img src="http:// img201.imageshack.us /img201/5206/ skellgriffot8.png" width="430" border="0" alt="" / Quote Link to comment Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 bump Quote Link to comment Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 in a very desprate attempt i tryed $regex = '/(<img.*?src="(.*?)".*?>)/'; preg_match($regex,$sb_message_txt,$match); foreach($regex as $regexs){ $picinfo = getimagesize($match[2]); $picinfo[0] = ($picinfo[0] > 430)? 430 : $picinfo[0]; $replacement = 'img src="'.$match[2].'" width="'.$picinfo[0].'" border="0" alt="" /'; $sb_message_txt=preg_replace($regexs, $replacement, $sb_message_txt); } LOL Obviously not working hahaha Quote Link to comment Share on other sites More sharing options...
.josh Posted December 17, 2008 Share Posted December 17, 2008 To match and replace all images in the string, you need to use preg_match_all and loop through each match. preg_match_all returns a different array structure than preg_match, because it has more than one match. Read the manual. <?php preg_match_all('/(<img.*?src="(.*?)".*?>)/',$message,$match); foreach($match[2] as $key => $pic) { $picinfo = getimagesize($pic); $picinfo[0] = ($picinfo[0] > 430)? 430 : $picinfo[0]; $replacement = 'img src="'.$pic.'" width="'.$picinfo[0].'" height="'.$picinfo[1].'" border="0" alt="" /'; $message = preg_replace($match[1][$key], $replacement, $message); } // end foreach Quote Link to comment Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 thx bro let me try that out Quote Link to comment Share on other sites More sharing options...
drisate Posted December 17, 2008 Author Share Posted December 17, 2008 worked great bro thx a lot. This will be really useful stuff to know Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.