Jump to content

Another BBcode Question


EZE

Recommended Posts

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;">
&nbsp;<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]
Link to comment
Share on other sites

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;">
&nbsp;<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("&#91", "&#93"), $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]
Link to comment
Share on other sites

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("&#91", "&#93"), $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]
Link to comment
Share on other sites

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("&#91", "&#93"), $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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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("&#91", "&#93"), $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]
Link to comment
Share on other sites

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]
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.