Jump to content

Small problem with bbcode


Rosst

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:
[code]<?
function bbcode($content)
{
    $bbcode = array(
      "'\[b\](.*?)\[/b\]'",
      "'\[i\](.*?)\[/i\]'",
      "'\[u\](.*?)\[/u\]'",
      "'\[code\](.+?)\[/code\]'",
      "'\[url=(.*?)\](.*?)\[/url\]'",
      "'\[url\](.*?)\[/url\]'",
      "'\[img\](.*?)\[/img\]'",
      "'\[red\](.*?)\[/red\]'",
      "':\)'",
      "':p'",
      "':o'",
      "':huh\?:'",
      "':C'",
      "':D'",
      "':lol:'",
      "':shades:'",
      "':blink:'",
      "':blush:'",
      "'!!'",
      "':check:'",
    );

    $html = array(
        "<b>\\1</b>",
        "<i>\\1</i>",
        "<u>\\1</u>",
        "<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;
}
?>[/code]
Thanks to anyone who can help!
Link to comment
Share on other sites

  • 2 weeks later...
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
Link to comment
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.
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.