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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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