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

    highlight_string(); by user input

    I'm creating a new forum.
    Similar to this forum, users will be able to use the "php" tags, I already have code that converts BBCODE to HTML, but I was just wondering how I would go about including a highlight_string(); php function into it?

    my code is currently this:

    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',
            
    => '/\[url\](.+?)\[\/url\]/s',
            
    => '/\[url\=(.+?)\](.+?)\[\/url\]/s',
            
    => '/\[img\](.+?)\[\/img\]/s',
            
    => '/\[color\=(.+?)\](.+?)\[\/color\]/s',
        
    => '/\[br\]/s',
        
    => '/\[hr\]/s',
            
    => '/\[center\](.+?)\[\/center\]/s',
            
    10 => '/\[size\=(.+?)\](.+?)\[\/size\]/s');

            
    $bbcode_replace = array(=> '<b>$1</b>',
            
    => '<i>$1</i>',
            
    => '<u>$1</u>',
            
    => '<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>',
            
    => '<br />',
        
    => '<hr />',
        
    => '<center>$1</center>',
            
    10 => '<span style="font-size:$1">$2</span>');

            
    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);
            
            
    $output preg_replace($bbcode_regex$bbcode_replace$post_abridged);
            
            
    $open '<table class="quote"><tr><td>';
            
    $close '</td></tr></table>';

            
    // How often is the open tag?
            
    preg_match_all ('/\[quote\]/i'$output$matches);
            
    $opentags count($matches['0']);

            
    // How often is the close tag?
            
    preg_match_all ('/\[\/quote\]/i'$output$matches);
            
    $closetags count($matches['0']);

            
    // Check how many tags have been unclosed
            // And add the unclosing tag at the end of the message
            
    $unclosed $opentags $closetags;
            for (
    $i 0$i $unclosed$i++) {
                    
    $output .= '</td></tr></table>';
            }

            
    // Do replacement
            
    $output str_replace ('[quote]'$open$output);
            
    $output str_replace ('[/quote]'$close$output);
            
            return 
    $output;
            
        } 

  • #2
    Regular Coder
    Join Date
    Sep 2006
    Posts
    122
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Anyone have any ideas?


  •  

    Posting Permissions

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