Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Setting [img][/img]

    I am having a lot of problems with this code When I try to use the [img][/img]
    it is showing the [img] in test and the url of the image instead of just showing the image I cant figure it out heres the code
    PHP Code:
        $quote2 str_replace("[center]","<center>"$quote2);
                        
    $quote2 str_replace("[/center]","</center>"$quote2);
                        
    $begin "";
                        
    $end strtolower($quote2);
                        while( !empty( 
    $end ) ) {
                            
    $p strposstrtolower$end ), "[img]");
                            if( 
    $p === FALSE ) {
                                
    $begin $begin $end;
                                
    $end "";
                            } else {
                                
    $begin $begin substr$end0$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$endstrlen$url ) );
                                
    $end substr$end,5);
                            }
                        }
    //                    $quote2 = $begin;
                        
    $quote2 str_replace("[/img]",""$quote2);
                        
    $quote2 str_replace("[/IMG]",""$quote2); 

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have fixed it

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Consider replacing BBCode style tags with regex instead. str_replace is faster than preg_replace, but when you need to add several lines of logic behind the str_replace it begins to take significantly more time and effort to create.
    The problem with str_replacements is its lack of control. With a preg you can ensure that both a start and an end tag have been supplied, which will keep it from breaking you're original html code.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •