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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts

    PHP to BBCode minor troubles

    I'm using the following code to convert BBCode to HTML:

    PHP Code:
        function output_post ($post) {
    $post_no_html htmlspecialchars($post);
    $post_abridged chop($post_no_html);
                              
    $bbcode_regex = array(=> '/\[b\](.+?)\[\/b\]/s',
                                                    
    => '/\[i\](.+?)\[\/i\]/s',
                                                    
    => '/\[u\](.+?)\[\/u\]/s',
                                                    
    => '/\[quote\](.+?)\[\/quote\]/s',
                                                    
    => '/\[quote\=(.+?)](.+?)\[\/quote\]/s',
                                                    
    => '/\[url\](.+?)\[\/url\]/s',
                                                    
    => '/\[url\=(.+?)\](.+?)\[\/url\]/s',
                                                    
    => '/\[img\](.+?)\[\/img\]/s',
                                                    
    => '/\[color\=(.+?)\](.+?)\[\/color\]/s',
                                                    
    => '/\[size\=(.+?)\](.+?)\[\/size\]/s',
                                                    
    10 => '/\[email\](.+?)\[\/email\]/s',
                                                    
    11 => '/\[email\=(.+?)](.+?)\[\/email\]/s',
                                                    
    12 => '/\[align\=(.+?)](.+?)\[\/align\]/s');

                            
    $bbcode_replace = array(=> '<b>$1</b>',
                                                    
    => '<i>$1</i>',
                                                    
    => '<u>$1</u>',
                                                    
    => '<table border="0" CELLSPACING="0" CELLPADDING="0"><TR><TD CLASS="quote">$1</TD><TR></TABLE><p>',
                                                    
    => '<table border="0" CELLSPACING="0" CELLPADDING="0"><TR><TD CLASS="quote">$1 said:<br> $2</TD><TR></TABLE><p>',
                                                    
    => '<a href="$1">$1</a>',
                                                    
    => '<a href="$1">$2</a>',
                                                    
    => '<img src="$1" alt="User submitted image" title="User submitted image"/>',
                                                    
    => '<span style="color:$1">$2</span>',
                                                    
    => '<span style="font-size:$1">$2</span>',
                                                    
    10 => '<a href="mailto:$1">$1</A>',
                                                    
    11 => '<a href="mailto:$1">$1</A>',
                                                    
    12 => '<p align=$1>$2</p>');

            
    ksort($bbcode_regex);
            
    ksort($bbcode_replace);

            
    //preg_replace to convert all remaining bbCode tags
            
    $post_bbcode_treated preg_replace($bbcode_regex$bbcode_replace$post_abridged);
    //Convert new lines to <br />
            
    $post_with_br nl2br($post_bbcode_treated);


            echo 
    $post_with_br;
    }; 
    <here the table opens fine>
    everything works perfectly except when a quote is inside another quote which looks like this:

    <this is where the table starts, and it works fine>
    Posted by User on November 06th, 2006 04:45 PM:
    <the random unchanged bbcode quote tag here>
    Posted by User on November 03rd, 2006 07:44 PM:
    message 1
    <here the table closes fine>

    Message 2

    <random unchanged closing bbcode tag here>

  • #2
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    anyone?

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    The reason this is happening is because the script is searching for the first [ quote ] and the next [ /quote ] and because of this, any quotes that go inside and outside of that get ignored.

    can anyone help me find a way round this?

  • #4
    Registered User
    Join Date
    Oct 2004
    Posts
    592
    Thanks
    0
    Thanked 1 Time in 1 Post
    My idea is to simply replace the with <textarea id="quote"></textarea>, and with <textarea id="code"></textarea>.

    Apply CSS for formatting as you like.
    For more details, download phpbb forum software from (http://prdownloads.sourceforge.net/p...mirror=surfnet)
    and learn their coversion coding.

    I attached it for you.
    Attached Files Attached Files


  •  

    Posting Permissions

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