Jump to content


Photo

Small problem with bbcode


  • Please log in to reply
5 replies to this topic

#1 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 13 September 2006 - 12:14 AM

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/in...cat=PHP&tutid=1
example of what I want it to look like: http://dannyscripts....tutorial&id=101
And my 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;
}
?>
Thanks to anyone who can help!

#2 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 13 September 2006 - 09:36 PM

Can anyone help?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 10:25 AM

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.

#4 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 17 September 2006 - 06:09 PM

I fixed it.. Thanks any way

#5 Rosst

Rosst
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 30 September 2006 - 03:55 AM

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/in...&cat=12&tutid=1 there it is, you can see, I am using the same code I posted before

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 30 September 2006 - 12:37 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users