Jump to content

Recommended Posts

Here's the script:

<?PHP
    //Functions
    function parseBBCode($data) {
        $BBCODE = array();
        $BBCODE_REPLACEMENT = array();
        $BBCODE[]             = '/\[i\](.*?)\[\/i\]/';
        $BBCODE_REPLACEMENT[] = '<em>$1</em>';
        $BBCODE[]             = '/\[u\](.*?)\[\/u\]/';
        $BBCODE_REPLACEMENT[] = '<span style="text-decoration: underline;">$1</span>';
        $BBCODE[]             = '/\[em\](.*?)\[\/em\]/';
        $BBCODE_REPLACEMENT[] = '<em>$1</em>';
        $BBCODE[]             = '/\[s\](.*?)\[\/s\]/';
        $BBCODE_REPLACEMENT[] = '<s>$1</s>';
        $BBCODE[]             = '/\[strong\](.*?)\[\/strong\]/';
        $BBCODE_REPLACEMENT[] = '<strong>$1</strong>';
        $BBCODE[]             = '/\[b\](.*?)\[\/b\]/';
        $BBCODE_REPLACEMENT[] = '<strong>$1</strong>';
        $BBCODE[]             = '/\[img\](.*?)\[\/img\]/';
        $BBCODE_REPLACEMENT[] = '<img src="$1" alt="User Posted Image" />';
        $BBCODE[]             = '/\[img=(.*?)\](.*?)\[\/img\]/';
        $BBCODE_REPLACEMENT[] = '<img src="$1" alt="User Posted Image" title="$2" />';
        //$BBCODE[]             = '/(http:\/\/[a-zA-Z0-9\?#\/\._\-\+=\|&;]+)/';
        //$BBCODE_REPLACEMENT[] = '[url=$1]Link[/url]';
        $BBCODE[]             = '/\[url=(.*?)\](.*?)\[\/url\]/';
        $BBCODE_REPLACEMENT[] = '<a href="$1" target="_blank">$2</a>';
        $BBCODE[]             = '/\[comment\](.*?)\[\/comment\]/';
        $BBCODE_REPLACEMENT[] = '<!-- $1 -->';
        $BBCODE[]             = '/\[heading=(.*?)\](.*?)\[\/heading\]/';
        $BBCODE_REPLACEMENT[] = '<h3 id="heading:$1"><a href="#heading:$1">$2</a></h3>';
        $BBCODE[]             = '/\[spoiler\](.*?)\[\/spoiler\]/';
        $BBCODE_REPLACEMENT[] = '{Spoiler:<span class="spoiler">$1</span>}';
        $BBCODE[]             = '/\[colou?r=(.*?)\](.*?)\[\/colou?r\]/';
        $BBCODE_REPLACEMENT[] = '<span style="color: $1;">$2</span>';
        $BBCODE[]             = '/\[quote\](.*?)\[\/quote\]/';
        $BBCODE_REPLACEMENT[] = '<div class="quote"><center>Quote:<br /><br />$1<br /></center></div>';
        $BBCODE[]             = '/\[quote=(.*?)\](.*?)\[\/quote\]/';
        $BBCODE_REPLACEMENT[] = '<div class="quote"><center><em>$1</em> said:<br /><br />$2<br /></center></div>';
        $BBCODE[]             = '/\[user\](.*?)\[\/user\]/';
        $BBCODE_REPLACEMENT[] = '<a href="viewprofile.php?id=$1" class="profileLink">$1</a>';
        $BBCODE[]             = '/\[collapse\](.*?)\[\/collapse\]/';
        $BBCODE_REPLACEMENT[] = '<div class="collapse">$1</div>';
        
        $SMILEYS = array();
        $SMILEYS_REPLACE = array();
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/smile.png"  alt="" />';
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/sad.png"  alt="" />';
        $SMILEYS[]         = ':@';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/angry.png"  alt=":@" />';
        $SMILEYS[]         = ':|';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/straightFace.png"  alt=":|" />';
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/shocked.png"  alt="" />';
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/wink.png"  alt="" />';
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/grin.png"  alt="" />';
        $SMILEYS[]         = '';
        $SMILEYS_REPLACE[] = '<img src="Images/smileys/tongue.png"  alt="" />';
        
        $CENSORS = array();
        $CENSORS_REPLACE = array();
        $CENSORS[] = 'fuck';
        $CENSORS_REPLACE[] = 'f***';
        $CENSORS[] = 'nigger';
        $CENSORS_REPLACE[] = 'n***er';
        $CENSORS[] = 'cock';
        $CENSORS_REPLACE[] = 'c**k';
        //Start with htmlentities
        $data = htmlentities($data);
//New lines, double spaces
        
$data = str_replace(array("\n",'  '),array('<br />','  '),$data);
        //Replace tags
        $data = preg_replace($BBCODE,$BBCODE_REPLACEMENT,$data);
        //Replace smileys
        $data = str_replace($SMILEYS,$SMILEYS_REPLACE,$data);
        //Replace curses
        $data = str_ireplace($CENSORS,$CENSORS_REPLACE,$data);
        return $data;
    }
?>

 

So.. the problem is.. Let's say I type:

 

[b][b][/b][/b]

 

It'll display it as:

[b][/b]

 

At first this doesnt seem like a problem, but its a HUGE problem with quotes.. Let's say I made a post like:

 

Hello

 

And quoted it

 

So in a div it says:

Xyphon said: Hello

 

And then I quote that message and it'll say in the div:

Xyphon said: [quote] Hello

And outside the div it says:

[/quote]

So it doesnt actually double quote..

 

Another problem is, sense I have the double space replacement, whenever I quote something with double space or new lines the message will be like:

Hi \n\n\n\r\n Hello

 

Please tell me how to fix these problems!! Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/
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.