Jump to content

Help with setting [img][/img]


Sideclef

Recommended Posts

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

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);  

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..

Archived

This topic is now archived and is 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.