EZE Posted January 27, 2007 Share Posted January 27, 2007 Okay, I have been trying to make a simple bbcode 'system', and it is going along good, but I am having trrouble with \[code\] bbcode tags. I have them replaced with a box that you can expand and collapse, and you can highlight the code. The problem is, I have named the divs for the code with id="ID", and thats how the javascript detects what boxes to expand and close. So, in other words, if I input code bbcode tags more tyhan once, if I click the collapse or expand, it collapses or expands all of the boxes. How can I stop this? With some sort of repeating number that adds +1 each time it is used? Here is my entire form file (Lots of extra lines are added by my php editor, sorry :-[):[code]<style type="text/css">body{ background-color:#006699; color:#FFFFFF; font-family:Arial, Helvetica, sans-serif; font-size:12;}a:link{ color: #FFFFFF; text-decoration: underline;}a:visited{ text-decoration: underline; color: #CCCCCC;}a:hover{ text-decoration: none; color: #942C2C;}a:active{ text-decoration: underline; color: #999999;}</style><body><script type="text/javascript">function menu(obj,expd,clp) {var element = document.getElementById(obj);if(element.style.display != 'none'){element.style.display = 'none';document.getElementById(expd).style.display = 'inline';document.getElementById(clp).style.display = 'none';}else{element.style.display = '';document.getElementById(expd).style.display = 'none';document.getElementById(clp).style.display = 'inline';}}function code_select(obj){ var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(document.getElementById(obj)); selection.removeAllRanges(); selection.addRange(range);}</script><? $self= $_SERVER['PHP_SELF']; $txt = $_POST['txt'];if( $txt == NULL ){$form ="<form method=\"post\" name=\"txt_check\" action=\"$self\">";$form.="Enter Some Text: ";$form.="<textarea name=\"txt\"></textarea> ";$form.="<input type=\"submit\" value=\"Submit\" onSubmit=\"this.value='Submitting...';this.disabled='true';\"/><br><input type=\"text\" name=\"helpbox\" size=\"75\" readonly=\"readonly\"/>"; echo $form;}else{ $bbsearch = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[s\](.*?)\[\/s\]/is', '/\[blink\](.*?)\[\/blink\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[email\](.*?)\[\/email\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[email\=(.*?)\](.*?)\[\/email\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size=xx-small\](.*?)\[\/size\]/is', '/\[size=x-small\](.*?)\[\/size\]/is', '/\[size=small\](.*?)\[\/size\]/is', '/\[size=medium\](.*?)\[\/size\]/is', '/\[size=large\](.*?)\[\/size\]/is', '/\[size=x-large\](.*?)\[\/size\]/is', '/\[size=xx-large\](.*?)\[\/size\]/is', '/\[align=left\](.*?)\[\/align\]/is', '/\[align=center\](.*?)\[\/align\]/is', '/\[align=right\](.*?)\[\/align\]/is', '/\[align=justified\](.*?)\[\/align\]/is', '/\[code\](.*?)\[\/code\]/is' ); $bbreplace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<s>$1</s>', '<blink>$1</blink>', '<a href="$1" target="_blank">$1</a>', '<a href="mailto:$1">$1</a>', '<a href="$1" target="_blank">$2</a>', '<a href="mailto:$1">$2</a>', '<img src="$1" border="0"/>', '<span style="color:$1;">$2</span>', '<span style="font-size: xx-small;">$1</span>', '<span style="font-size: x-small;">$1</span>', '<span style="font-size: small;">$1</span>', '<span style="font-size: medium;">$1</span>', '<span style="font-size: large;">$1</span>', '<span style="font-size: x-large;">$1</span>', '<span style="font-size: xx-large;">$1</span>', '<div style="text-align: left;">$1</div>', '<div style="text-align: center;">$1</div>', '<div style="text-align: right;">$1</div>', '<div style="text-align: justified;">$1</div>', '<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu(\'code1\',\'expand1\',\'collapse1\');" title="Show Or Hide This Code"><span id="expand1" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span><span id="collapse1" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span></a> Code :: <a href="javascript:code_select(\'code1\');" title="Highlight The Code">Select Code</a> </div> <div id="code1"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>$1</code></div> </div></div>' ); $msg = htmlentities($txt); $msg = stripslashes($txt); $msg = nl2br($msg); $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}?>[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 27, 2007 Share Posted January 27, 2007 Its mainly the way you parse your code BBCodes. What you are doing is parsing them as "static" text, want to do is parse them dynamically - meaning give each code box there own unique id. In order to do that you need to change the way you are parsing your code BBcodes slightly. Here intructions in doing so.Change the following:[code]'/\[align=justified\](.*?)\[\/align\]/is','/\[code\](.*?)\[\/code\]/is');[/code]To this:[code]'/\[align=justified\](.*?)\[\/align\]/is');[/code]Now change this:[code] '<div style="text-align: justified;">$1</div>', '<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu(\'code1\',\'expand1\',\'collapse1\');" title="Show Or Hide This Code"><span id="expand1" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span><span id="collapse1" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span></a> Code :: <a href="javascript:code_select(\'code1\');" title="Highlight The Code">Select Code</a> </div> <div id="code1"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>$1</code></div> </div></div>' );[/code]To this:[code] '<div style="text-align: justified;">$1</div>' );[/code]The final change is to change this:[code] $msg = htmlentities($txt); $msg = stripslashes($txt); $msg = nl2br($msg); $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}[/code]to this:[code] function makeCodeBox($code, $cID) { $code = str_replace(array("[", "]"), array("[", "]"), $code); $html = <<<HTML<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu('code{$cID}','expand{$cID}','collapse{$cID}');" title="Show Or Hide This Code"> <span id="expand{$cID}" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span> <span id="collapse{$cID}" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span> </a> Code :: <a href="javascript:code_select('code{$cID}');" title="Highlight The Code">Select Code</a> </div> <div id="code{$cID}"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>{$code}</code></div> </div></div>HTML; return $html; } $msg = htmlentities($msg); $msg = stripslashes($msg); $msg = nl2br($msg); $i = 0; while(preg_match("/\[code\](.*?)\[\/code\]/ise", $msg, $matches)) { $i++; $msg = str_replace($matches[0], makeCodeBox($matches[1], $i), $msg); } $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}[/code] Quote Link to comment Share on other sites More sharing options...
EZE Posted January 27, 2007 Author Share Posted January 27, 2007 Okay, i did that, and no parse errors come up, but any text I enter doesn't show up anymore. Here is my entire new code: [code]<style type="text/css">body{ background-color:#006699; color:#FFFFFF; font-family:Arial, Helvetica, sans-serif; font-size:12;}a:link{ color: #FFFFFF; text-decoration: underline;}a:visited{ text-decoration: underline; color: #CCCCCC;}a:hover{ text-decoration: none; color: #942C2C;}a:active{ text-decoration: underline; color: #999999;}</style><body><script type="text/javascript">function menu(obj,expd,clp) {var element = document.getElementById(obj);if(element.style.display != 'none'){element.style.display = 'none';document.getElementById(expd).style.display = 'inline';document.getElementById(clp).style.display = 'none';}else{element.style.display = '';document.getElementById(expd).style.display = 'none';document.getElementById(clp).style.display = 'inline';}}function code_select(obj){ var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(document.getElementById(obj)); selection.removeAllRanges(); selection.addRange(range);}</script><? $self= $_SERVER['PHP_SELF']; $txt = $_POST['txt'];if( $txt == NULL ){$form ="<form method=\"post\" name=\"txt_check\" action=\"$self\">";$form.="Enter Some Text: ";$form.="<textarea name=\"txt\"></textarea> ";$form.="<input type=\"submit\" value=\"Submit\" onSubmit=\"this.value='Submitting...';this.disabled='true';\"/><br>"; echo $form;}else{ $bbsearch = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[s\](.*?)\[\/s\]/is', '/\[blink\](.*?)\[\/blink\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[email\](.*?)\[\/email\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[email\=(.*?)\](.*?)\[\/email\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size=xx-small\](.*?)\[\/size\]/is', '/\[size=x-small\](.*?)\[\/size\]/is', '/\[size=small\](.*?)\[\/size\]/is', '/\[size=medium\](.*?)\[\/size\]/is', '/\[size=large\](.*?)\[\/size\]/is', '/\[size=x-large\](.*?)\[\/size\]/is', '/\[size=xx-large\](.*?)\[\/size\]/is', '/\[align=left\](.*?)\[\/align\]/is', '/\[align=center\](.*?)\[\/align\]/is', '/\[align=right\](.*?)\[\/align\]/is', '/\[align=justified\](.*?)\[\/align\]/is' ); $bbreplace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<s>$1</s>', '<blink>$1</blink>', '<a href="$1" target="_blank">$1</a>', '<a href="mailto:$1">$1</a>', '<a href="$1" target="_blank">$2</a>', '<a href="mailto:$1">$2</a>', '<img src="$1" border="0"/>', '<span style="color:$1;">$2</span>', '<span style="font-size: xx-small;">$1</span>', '<span style="font-size: x-small;">$1</span>', '<span style="font-size: small;">$1</span>', '<span style="font-size: medium;">$1</span>', '<span style="font-size: large;">$1</span>', '<span style="font-size: x-large;">$1</span>', '<span style="font-size: xx-large;">$1</span>', '<div style="text-align: left;">$1</div>', '<div style="text-align: center;">$1</div>', '<div style="text-align: right;">$1</div>', '<div style="text-align: justified;">$1</div>', );function makeCodeBox($code, $cID) { $code = str_replace(array("[", "]"), array("[", "]"), $code); $html = <<<HTML<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu('code{$cID}','expand{$cID}','collapse{$cID}');" title="Show Or Hide This Code"> <span id="expand{$cID}" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span> <span id="collapse{$cID}" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span> </a> Code :: <a href="javascript:code_select('code{$cID}');" title="Highlight The Code">Select Code</a> </div> <div id="code{$cID}"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>{$code}</code></div> </div></div>HTML; return $html; } $msg = htmlentities($msg); $msg = stripslashes($msg); $msg = nl2br($msg); $i = 0; while(preg_match("/\[code\](.*?)\[\/code\]/ise", $msg, $matches)) { $i++; $msg = str_replace($matches[0], makeCodeBox($matches[1], $i), $msg); } $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}?>[/code] Quote Link to comment Share on other sites More sharing options...
EZE Posted January 29, 2007 Author Share Posted January 29, 2007 *bump* Help Please! Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 29, 2007 Share Posted January 29, 2007 I forgot to mention to change the following:[code]$txt = @$_POST['txt'];if( $txt == NULL ){[/code]to this:[code]if(isset($_POST['txt']) { $msg = $_POST['txt'];[/code]Always use isset when checking $_POST and $_GET variables. Quote Link to comment Share on other sites More sharing options...
EZE Posted January 29, 2007 Author Share Posted January 29, 2007 That didn't work. I tried it and it said parse error unexpected "{" on line 52. Here is my long re-written code. [code]<style type="text/css">body{ background-color:#006699; color:#FFFFFF; font-family:Arial, Helvetica, sans-serif; font-size:12;}a:link{ color: #FFFFFF; text-decoration: underline;}a:visited{ text-decoration: underline; color: #CCCCCC;}a:hover{ text-decoration: none; color: #942C2C;}a:active{ text-decoration: underline; color: #999999;}</style><body><script type="text/javascript">function menu(obj,expd,clp) {var element = document.getElementById(obj);if(element.style.display != 'none'){element.style.display = 'none';document.getElementById(expd).style.display = 'inline';document.getElementById(clp).style.display = 'none';}else{element.style.display = '';document.getElementById(expd).style.display = 'none';document.getElementById(clp).style.display = 'inline';}}function code_select(obj){ var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(document.getElementById(obj)); selection.removeAllRanges(); selection.addRange(range);}</script><? $self= $_SERVER['PHP_SELF'];if(isset($_POST['txt']) { $msg = $_POST['txt'];$form ="<form method=\"post\" name=\"txt_check\" action=\"$self\">";$form.="Enter Some Text: ";$form.="<textarea name=\"txt\"></textarea> ";$form.="<input type=\"submit\" value=\"Submit\" onSubmit=\"this.value='Submitting...';this.disabled='true';\"/><br>"; echo $form;}else{ $bbsearch = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[s\](.*?)\[\/s\]/is', '/\[blink\](.*?)\[\/blink\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[email\](.*?)\[\/email\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[email\=(.*?)\](.*?)\[\/email\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size=xx-small\](.*?)\[\/size\]/is', '/\[size=x-small\](.*?)\[\/size\]/is', '/\[size=small\](.*?)\[\/size\]/is', '/\[size=medium\](.*?)\[\/size\]/is', '/\[size=large\](.*?)\[\/size\]/is', '/\[size=x-large\](.*?)\[\/size\]/is', '/\[size=xx-large\](.*?)\[\/size\]/is', '/\[align=left\](.*?)\[\/align\]/is', '/\[align=center\](.*?)\[\/align\]/is', '/\[align=right\](.*?)\[\/align\]/is', '/\[align=justified\](.*?)\[\/align\]/is' ); $bbreplace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<s>$1</s>', '<blink>$1</blink>', '<a href="$1" target="_blank">$1</a>', '<a href="mailto:$1">$1</a>', '<a href="$1" target="_blank">$2</a>', '<a href="mailto:$1">$2</a>', '<img src="$1" border="0"/>', '<span style="color:$1;">$2</span>', '<span style="font-size: xx-small;">$1</span>', '<span style="font-size: x-small;">$1</span>', '<span style="font-size: small;">$1</span>', '<span style="font-size: medium;">$1</span>', '<span style="font-size: large;">$1</span>', '<span style="font-size: x-large;">$1</span>', '<span style="font-size: xx-large;">$1</span>', '<div style="text-align: left;">$1</div>', '<div style="text-align: center;">$1</div>', '<div style="text-align: right;">$1</div>', '<div style="text-align: justified;">$1</div>', );function makeCodeBox($code, $cID) { $code = str_replace(array("[", "]"), array("[", "]"), $code); $html = <<<HTML<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu('code{$cID}','expand{$cID}','collapse{$cID}');" title="Show Or Hide This Code"> <span id="expand{$cID}" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span> <span id="collapse{$cID}" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span> </a> Code :: <a href="javascript:code_select('code{$cID}');" title="Highlight The Code">Select Code</a> </div> <div id="code{$cID}"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>{$code}</code></div> </div></div>HTML; return $html; } $msg = htmlentities($msg); $msg = stripslashes($msg); $msg = nl2br($msg); $i = 0; while(preg_match("/\[code\](.*?)\[\/code\]/ise", $msg, $matches)) { $i++; $msg = str_replace($matches[0], makeCodeBox($matches[1], $i), $msg); } $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}?>[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted January 30, 2007 Share Posted January 30, 2007 And line 52 is? This is a simple parsing error, look for matching braces. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 30, 2007 Share Posted January 30, 2007 Oh pants! I left out a closing [b])[/b] on the if statement.Change this:[code]if(isset($_POST['txt']) {[/code]to this:[code]if(isset($_POST['txt'])) {[/code]It should be fine now *crosses figures* Quote Link to comment Share on other sites More sharing options...
EZE Posted January 30, 2007 Author Share Posted January 30, 2007 Okay, now it says there is an error on line 198, with my echo statement. The only code I changed was the one you said above, but now it says there is a an error with this: [code] echo "Why Did You Write $msg?";[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 31, 2007 Share Posted January 31, 2007 Here use this instead:[code]<style type="text/css">body{ background-color:#006699; color:#FFFFFF; font-family:Arial, Helvetica, sans-serif; font-size:12;}a:link{ color: #FFFFFF; text-decoration: underline;}a:visited{ text-decoration: underline; color: #CCCCCC;}a:hover{ text-decoration: none; color: #942C2C;}a:active{ text-decoration: underline; color: #999999;}</style><script type="text/javascript">function menu(obj,expd,clp) { var element = document.getElementById(obj); if(element.style.display != 'none') { element.style.display = 'none'; document.getElementById(expd).style.display = 'inline'; document.getElementById(clp).style.display = 'none'; } else { element.style.display = ''; document.getElementById(expd).style.display = 'none'; document.getElementById(clp).style.display = 'inline'; }}function code_select(obj) { var selection = window.getSelection(); var range = document.createRange(); range.selectNodeContents(document.getElementById(obj)); selection.removeAllRanges(); selection.addRange(range);}</script><body><?php$self = $_SERVER['PHP_SELF'];if(!isset($_POST['txt'])){ $form ="<form method=\"post\" name=\"txt_check\" action=\"$self\">"; $form.="Enter Some Text: "; $form .= "<textarea name=\"txt\"></textarea> "; $form .= "<input type=\"submit\" value=\"Submit\" onSubmit=\"this.value='Submitting...';this.disabled='true';\"/><br>"; echo $form;}else{ $msg = $_POST['txt']; $bbsearch = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[s\](.*?)\[\/s\]/is', '/\[blink\](.*?)\[\/blink\]/is', '/\[url\](.*?)\[\/url\]/is', '/\[email\](.*?)\[\/email\]/is', '/\[url\=(.*?)\](.*?)\[\/url\]/is', '/\[email\=(.*?)\](.*?)\[\/email\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', '/\[size=xx-small\](.*?)\[\/size\]/is', '/\[size=x-small\](.*?)\[\/size\]/is', '/\[size=small\](.*?)\[\/size\]/is', '/\[size=medium\](.*?)\[\/size\]/is', '/\[size=large\](.*?)\[\/size\]/is', '/\[size=x-large\](.*?)\[\/size\]/is', '/\[size=xx-large\](.*?)\[\/size\]/is', '/\[align=left\](.*?)\[\/align\]/is', '/\[align=center\](.*?)\[\/align\]/is', '/\[align=right\](.*?)\[\/align\]/is', '/\[align=justified\](.*?)\[\/align\]/is'); $bbreplace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<s>$1</s>', '<blink>$1</blink>', '<a href="$1" target="_blank">$1</a>', '<a href="mailto:$1">$1</a>', '<a href="$1" target="_blank">$2</a>', '<a href="mailto:$1">$2</a>', '<img src="$1" border="0"/>', '<span style="color:$1;">$2</span>', '<span style="font-size: xx-small;">$1</span>', '<span style="font-size: x-small;">$1</span>', '<span style="font-size: small;">$1</span>', '<span style="font-size: medium;">$1</span>', '<span style="font-size: large;">$1</span>', '<span style="font-size: x-large;">$1</span>', '<span style="font-size: xx-large;">$1</span>', '<div style="text-align: left;">$1</div>', '<div style="text-align: center;">$1</div>', '<div style="text-align: right;">$1</div>', '<div style="text-align: justified;">$1</div>' ); function makeCodeBox($code, $cID) { $code = str_replace(array("[", "]"), array("[", "]"), $code); $html = <<<HTML<div style="border:1px solid #000000;display:table;width:350;margin:0px auto;"> <div style="background-image:url(code_top.png);background-repeat:repeat-x;"> <a href="javascript:menu('code{$cID}','expand{$cID}','collapse{$cID}');" title="Show Or Hide This Code"> <span id="expand{$cID}" style="display:none;"><img src="expand.gif" width="9" height="9" alt="[-]" border="0"/></span> <span id="collapse{$cID}" display="inline"><img src="collapse.gif" width="9" height="9" alt="[-]" border="0"/></span> </a> Code :: <a href="javascript:code_select('code{$cID}');" title="Highlight The Code">Select Code</a> </div> <div id="code{$cID}"> <div style="background-color:#000000;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#5A2323;height:1px;width:100%;font-size:0;"></div> <div style="background-color:#470A0A;"><code>{$code}</code></div> </div></div>HTML; return $html; } $msg = htmlentities($msg); $msg = stripslashes($msg); $msg = nl2br($msg); $i = 0; while(preg_match("/\[code\](.*?)\[\/code\]/ise", $msg, $matches)) { $i++; $msg = str_replace($matches[0], makeCodeBox($matches[1], $i), $msg); } $msg = preg_replace($bbsearch, $bbreplace, $msg); echo "Why Did You Write $msg?";}?>[/code] Quote Link to comment Share on other sites More sharing options...
EZE Posted January 31, 2007 Author Share Posted January 31, 2007 Awesome! It works now! Okay, one little addition I want to add though. If the user hasn't inputted [/code], then php automatically puts it in in the end of the 'post'. How can I do this? With all of my bbcode, including [code][code][/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 31, 2007 Share Posted January 31, 2007 Then you will need to check that there are equal [nobbc][code][/nobbc] and [nobbc][/code][/nobbc] tags in the post. If there aren't then you will need to add in [nobbc][/code][/nobbc] to the end of the post and then parse the code tags. Quote Link to comment 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.