Sideclef Posted August 13, 2008 Share Posted August 13, 2008 I am having a lot of problems with this code When I try to use the [/img] it is showing the in test and the url of the image instead of just showing the image this is what shows http://i164.photobucket.com/albums/u13/smzbjb/something.png I cant figure it out heres the code $quote2 = str_replace(" [center]","<center>", $quote2); $quote2 = str_replace("[/center] ","</center>", $quote2); $begin = ""; $end = strtolower($quote2); while( !empty( $end ) ) { $p = strpos( strtolower( $end ), "[img]"); if( $p === FALSE ) { $begin = $begin . $end; $end = ""; } else { $begin = $begin . substr( $end, 0, $p ); $end = substr( $end, $p ); $p = strpos( $end, "[/img]" ); if( $p === FALSE ) { $p = strlen( $end ); } $p = ($p - 5); $url = substr( $end,5, $p ); list($width, $height, $type, $attr) = @getimagesize( $url ); if ($width > 450) { $begin = $begin . "<center><img width=450 src=\"$url\"><br/></center>"; } else { $begin = $begin . "<center><img % src=\"$url\"></center>"; } $end = substr( $end, strlen( $url ) ); $end = substr( $end,5); } } // $quote2 = $begin; $quote2 = str_replace("[/img]","", $quote2); $quote2 = str_replace("[/img]","", $quote2); Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/ Share on other sites More sharing options...
Sideclef Posted August 13, 2008 Author Share Posted August 13, 2008 sorry I messed up the post here it is corrected I am having problems getting the code to work it shows [img] http://i164.photobucket.com/albums/u13/smzbjb/something.png as the result instaed of showing the image I have no idea whats wrong been working on it for days. $quote2 = str_replace(" [center]","<center>", $quote2); $quote2 = str_replace("[/center] ","</center>", $quote2); $begin = ""; $end = strtolower($quote2); while( !empty( $end ) ) { $p = strpos( strtolower( $end ), "[img]"); if( $p === FALSE ) { $begin = $begin . $end; $end = ""; } else { $begin = $begin . substr( $end, 0, $p ); $end = substr( $end, $p ); $p = strpos( $end, "[/img]" ); if( $p === FALSE ) { $p = strlen( $end ); } $p = ($p - 5); $url = substr( $end,5, $p ); list($width, $height, $type, $attr) = @getimagesize( $url ); if ($width > 450) { $begin = $begin . "<center><img width=450 src=\"$url\"><br/></center>"; } else { $begin = $begin . "<center><img % src=\"$url\"></center>"; } $end = substr( $end, strlen( $url ) ); $end = substr( $end,5); } } // $quote2 = $begin; $quote2 = str_replace("[/img]","", $quote2); $quote2 = str_replace("[/img]","", $quote2); Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/#findComment-615592 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Why not just use a regex...? <?php $text = "[img=http://i164.photobucket.com/albums/u13/smzbjb/something.png]"; preg_replace('/[img](.+?)[\/img]/i', '<img src="$1" />', $text); ?> Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/#findComment-615596 Share on other sites More sharing options...
Sideclef Posted August 13, 2008 Author Share Posted August 13, 2008 I fixed it thanks for the help Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/#findComment-615706 Share on other sites More sharing options...
thebadbad Posted August 13, 2008 Share Posted August 13, 2008 Why not just use a regex...? <?php $text = "[img=http://i164.photobucket.com/albums/u13/smzbjb/something.png]"; preg_replace('/[img](.+?)[\/img]/i', '<img src="$1" />', $text); ?> You forgot to escape the square brackets. Just in case the OP is using your code.. Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/#findComment-615726 Share on other sites More sharing options...
DarkWater Posted August 13, 2008 Share Posted August 13, 2008 Yeah, I know. >_< I realized it after my editing time was over, lol. I tried it and realized "oh hey it didn't work, let me escape those". Link to comment https://forums.phpfreaks.com/topic/119495-help-with-setting-imgimg/#findComment-615737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.