Jump to content


This topic is now archived and is closed to further replies.


Small problem with bbcode

Recommended Posts

Hello, I have a small problem with my bbcode, I got it fixed here at php freaks, and I thought it was OK the way it was, what happens is when I use bbcode there are massive spaces between lines, and I need that to be fixed, example of what it looks like: http://vexxon.net/index.php?id=tuts&cat=PHP&tutid=1
example of what I want it to look like: http://dannyscripts.com/?view=tutorials&act=tutorial&id=101
And my code:
function bbcode($content)
    $bbcode = array(

    $html = array(
        "<strong>Code:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #000000;width:80%;\"></em>\\1</em></div>",
        "<a href=\"\\1\" target=\"_BLANK\">\\2</a>",
        "<a href=\"\\1\" target=\"_BLANK\">\\1</a>",
        "<img border=\"0\" src=\"\\1\">",
        "<font color=\"#FF6600\">\\1</font>",
        "<img src=\"includes/smileys/smile.gif\">",
        "<img src=\"includes/smileys/tongue.gif\">",
        "<img src=\"includes/smileys/ohmy.gif\">",
        "<img src=\"includes/smileys/huh.gif\">",
        "<img src=\"includes/smileys/angry.gif\">",
        "<img src=\"includes/smileys/biggrin.gif\">",
        "<img src=\"includes/smileys/laugh.gif\">",
        "<img src=\"includes/smileys/cool.gif\">",
        "<img src=\"includes/smileys/blink.gif\">",
        "<img src=\"includes/smileys/blush.gif\">",
        "<img src=\"includes/smileys/!!.gif\">",
        "<img src=\"includes/smileys/check.gif\">",

    $content = preg_replace($bbcode, $html, $content);

    // call a dedicated function to highlight our php code.
    $content = preg_replace_callback("#\[php\](.*?)\[\/php\]#is", 'highlight_php', $content);

    return stripslashes(nl2br($content));
function highlight_php($matches)
    $php = "<strong>PHP:</strong><div style=\"margin:0px 10px;padding:5px;border:1px dotted #000000;width:80%;\"></em>";
    $php .= highlight_string($matches[0], true);
    $php .= '</em></div>';
    //strip out line breaks:
    $php = str_replace("<br />", '', $php);
    // strip out PHP BBCode tags:
    $php = preg_replace("#(\[php\]|\[/php\])#i", "", $php);

    return $php;
Thanks to anyone who can help!

Share this post

Link to post
Share on other sites
I do not see the problem. The highlighted PHP code looks fine to me, and is more readable compared to the site you have linked to.

Could you define what you mean by massive spaces between lines.

Share this post

Link to post
Share on other sites
Hmm, I need help again, see right now I am looking at one of the tutorials I posted on my site and I see [code=php:0] in it, but it shouldn't be there, and there is a gap at the top, does anyone know how to fix it? Sometimes it doesn't even highlight it... http://vexxon.net/index.php?id=tuts&cat=12&tutid=1 there it is, you can see, I am using the same code I posted before

Share this post

Link to post
Share on other sites
Could you post the code here for the highlight_php function. Also the C/C++ code will not be highlighted as its is not php code, and the highlight_string functionwill only highlight the php code if you add the php tags in (<?(php) ?>) if the open/closing php tags are not there the highlight_string function will not highlight the php code.

Share this post

Link to post
Share on other sites


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.