Xyphon Posted June 22, 2009 Share Posted June 22, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/ Share on other sites More sharing options...
Xyphon Posted June 22, 2009 Author Share Posted June 22, 2009 BuMp Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-861567 Share on other sites More sharing options...
Andy-H Posted June 22, 2009 Share Posted June 22, 2009 for the newlines you can use nl2br() http://php.net/nl2br Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-861570 Share on other sites More sharing options...
Xyphon Posted June 22, 2009 Author Share Posted June 22, 2009 Yeah I know but that won't do double spaces. Anyway, right now that's not my top priority, the first problem is. Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-861583 Share on other sites More sharing options...
Xyphon Posted June 23, 2009 Author Share Posted June 23, 2009 Bump Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-862124 Share on other sites More sharing options...
Daniel0 Posted June 23, 2009 Share Posted June 23, 2009 BuMp RuLeS Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-862130 Share on other sites More sharing options...
Xyphon Posted June 23, 2009 Author Share Posted June 23, 2009 Sorry about that.. But, the second bump had the post 2 pages back, on page 3. And, no, I didn't have additional information. But I didn't wanna recreate this post. Quote Link to comment https://forums.phpfreaks.com/topic/163291-bb-code-script-wont-double-tag/#findComment-862136 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.