Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

How to fix bug in bbcode .

Hello

i make code my forums, i use bbcode and found bug <br />
how to not add <br / > in

Open in new window


        function bbcode_format ($str) {  
           // $str = htmlentities($str);  ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
              $str = htmlspecialchars($str);
          
            $simple_search = array(  
                        //added line break  
                        '/\[br\]/is',  
                        '/\[b\](.*?)\[\/b\]/is',  
                        '/\[i\](.*?)\[\/i\]/is',  
                        '/\[u\](.*?)\[\/u\]/is',  
                        '/\[url\=(.*?)\](.*?)\[\/url\]/is',  
                        '/\[url\](.*?)\[\/url\]/is',  
                        '/\[align\=(left|center|right)\](.*?)\[\/align\]/is',  
                        '/\[img\](.*?)\[\/img\]/is',  
                        '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',  
                        '/\[mail\](.*?)\[\/mail\]/is',  
                        '/\[font\=(.*?)\](.*?)\[\/font\]/is',  
                        '/\[size\=(.*?)\](.*?)\[\/size\]/is',  
                        '/\[color\=(.*?)\](.*?)\[\/color\]/is',  
                          //added textarea for code presentation  
                       '/\[codearea\](.*?)\[\/codearea\]/is',  
                         //added pre class for code presentation  
                      '/\[code\](.*?)\[\/code\]/is',  
                        //added paragraph  
                      '/\[p\](.*?)\[\/p\]/is',  
                        );  
          
            $simple_replace = array(  
                        //added line break  
                       '<br />',  
                        '<strong>$1</strong>',  
                        '<em>$1</em>',  
                        '<u>$1</u>',  
                        // added nofollow to prevent spam  
                        '<a href="$1" rel="nofollow" title="$2 - $1"  target="_blank">$2</a>',  
                        '<a href="$1" rel="nofollow" title="$1"  target="_blank">$1</a>',  
                        '<div style="text-align: $1;">$2</div>',  
                        //added alt attribute for validation  
                        '<a href="$1" rel="nofollow" target="_blank"><img  class="thumb" src="$1" alt="http://www.ai4investment.com" /></a>',  
                        '<a href="mailto:$1"  target="_blank">$2</a>',  
                        '<a href="mailto:$1"  target="_blank">$1</a>',  
                        '<span style="font-family: $1;">$2</span>',  
                        '<span style="font-size: $1;">$2</span>',  
                        '<span style="color: $1;">$2</span>',  
                        //added textarea for code presentation  
                        '<textarea class="code_container" rows="30" cols="70">$1</textarea>',  
                        //added pre class for code presentation  
                        '<pre class="brush: cpp">$1</pre>',  
                        //added paragraph  
                        '<p>$1</p>',  
                        );  
          
            // Do simple BBCode's  
            $str = preg_replace ($simple_search, $simple_replace, $str);  
          
            // Do <blockquote> BBCode  
            $str = $this->bbcode_quote ($str);  
            $bbcode = nl2br($str);
          
            return $bbcode;  
        }     

Open in new window

0
XSoFTz
Asked:
XSoFTz
  • 5
  • 4
1 Solution
 
ahoffmannCommented:
> ... how to not add <br / > 
remove first array element in both arrays
0
 
XSoFTzAuthor Commented:
i mean

$bbcode = nl2br($str);

Open in new window


but i need add nl2br then check in bbcode [ code ][ /code ] and not add nl2br ?
0
 
ahoffmannCommented:
hmm, don't know what nl2br() does, assuming that it converts 0x0a to <br > then according your question:
> ... how to not add <br / > 
simply do not call it

may be I don't understand what you want to archive, but your description is very vage ...
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
XSoFTzAuthor Commented:
about code it work but.

in tag code

[ code ]
if()
{

}
[ /code ]

PHP Code Line :

$bbcode = nl2br($str);

Output :

[ code ]
if()<br />
{<br />
<br />
}<br />
[ /code ]

it add <br /> in code. but i not need <br /> add in tag code

then not use nl2br() function, in tag \n not work display on html code.
0
 
ahoffmannCommented:
you need to parse your code and exclude those parts which you define as code from being passed to nl2br()

You need a good parser for that as it cannot simply be done with regex, see this example

[ code ]
if(x=="[ /code ]"){
  bang="\
[ code ]  \
";
/*
[ /code ]
*/
hidden=true;
}
[ /code ]
0
 
XSoFTzAuthor Commented:
not so it .

see

DisplayHtml Code
i not get <br /> in tag [ code ]

in bbcode :

[ code ]
int start() {
   if (gs_108 != gs_100) return (0);
   int ind_counted_0 = IndicatorCounted();
   int li_8 = Bars - ind_counted_0;
   if (li_8 > 1) li_8 = Bars - 3;
   double ld_12 = p / 100.0;
   for (int li_4 = li_8; li_4 >= 0; li_4--) {
      if (Close[li_4] < gd_132) {
         gd_132 = Close[li_4];
         gd_148 = gd_132 * (2.0 * ld_12 + 1.0);
         gd_140 = gd_132 * (ld_12 + 1.0);
      }
      if (Close[li_4] > gd_148) {
         gd_148 = Close[li_4];
         gd_132 = gd_148 * (1 - 2.0 * ld_12);
         gd_140 = gd_148 * (1 - ld_12);
      }
      g_ibuf_120[li_4] = gd_148;
      g_ibuf_124[li_4] = gd_140;
      g_ibuf_128[li_4] = gd_132;
   }
   return (0);
}
[ /code ]
0
 
ahoffmannCommented:
> i not get <br /> in tag [ code ]
I'm confused, what exactly is your problem then?
can you please give an example verbatime what you have, what you expect and what you get (which is buggy in your opinion)
0
 
XSoFTzAuthor Commented:
now i need fix bug..

1. put bbcode in my code
[ code ]
int start() {
   if (gs_108 != gs_100) return (0);
   int ind_counted_0 = IndicatorCounted();
   int li_8 = Bars - ind_counted_0;
   if (li_8 > 1) li_8 = Bars - 3;
   double ld_12 = p / 100.0;
   for (int li_4 = li_8; li_4 >= 0; li_4--) {
      if (Close[li_4] < gd_132) {
         gd_132 = Close[li_4];
         gd_148 = gd_132 * (2.0 * ld_12 + 1.0);
         gd_140 = gd_132 * (ld_12 + 1.0);
      }
      if (Close[li_4] > gd_148) {
         gd_148 = Close[li_4];
         gd_132 = gd_148 * (1 - 2.0 * ld_12);
         gd_140 = gd_148 * (1 - ld_12);
      }
      g_ibuf_120[li_4] = gd_148;
      g_ibuf_124[li_4] = gd_140;
      g_ibuf_128[li_4] = gd_132;
   }
   return (0);
}
[ /code ]

Open in new window



2. i use function

function bbcode_format ($str) {  
           // $str = htmlentities($str);  ¿¿¿¿¿¿¿¿¿¿¿¿¿¿¿
              $str = htmlspecialchars($str);
          
            $simple_search = array(  
                        //added line break  
                        '/\[br\]/is',  
                        '/\[b\](.*?)\[\/b\]/is',  
                        '/\[i\](.*?)\[\/i\]/is',  
                        '/\[u\](.*?)\[\/u\]/is',  
                        '/\[url\=(.*?)\](.*?)\[\/url\]/is',  
                        '/\[url\](.*?)\[\/url\]/is',  
                        '/\[align\=(left|center|right)\](.*?)\[\/align\]/is',  
                        '/\[img\](.*?)\[\/img\]/is',  
                        '/\[mail\=(.*?)\](.*?)\[\/mail\]/is',  
                        '/\[mail\](.*?)\[\/mail\]/is',  
                        '/\[font\=(.*?)\](.*?)\[\/font\]/is',  
                        '/\[size\=(.*?)\](.*?)\[\/size\]/is',  
                        '/\[color\=(.*?)\](.*?)\[\/color\]/is',  
                          //added textarea for code presentation  
                       '/\[codearea\](.*?)\[\/codearea\]/is',  
                         //added pre class for code presentation  
                      '/\[code\](.*?)\[\/code\]/is',  
                        //added paragraph  
                      '/\[p\](.*?)\[\/p\]/is',  
                        );  
          
            $simple_replace = array(  
                        //added line break  
                       '<br />',  
                        '<strong>$1</strong>',  
                        '<em>$1</em>',  
                        '<u>$1</u>',  
                        // added nofollow to prevent spam  
                        '<a href="$1" rel="nofollow" title="$2 - $1"  target="_blank">$2</a>',  
                        '<a href="$1" rel="nofollow" title="$1"  target="_blank">$1</a>',  
                        '<div style="text-align: $1;">$2</div>',  
                        //added alt attribute for validation  
                        '<a href="$1" rel="nofollow" target="_blank"><img  class="thumb" src="$1" alt="http://www.ai4investment.com" /></a>',  
                        '<a href="mailto:$1"  target="_blank">$2</a>',  
                        '<a href="mailto:$1"  target="_blank">$1</a>',  
                        '<span style="font-family: $1;">$2</span>',  
                        '<span style="font-size: $1;">$2</span>',  
                        '<span style="color: $1;">$2</span>',  
                        //added textarea for code presentation  
                        '<textarea class="code_container" rows="30" cols="70">$1</textarea>',  
                        //added pre class for code presentation  
                        '<pre class="brush: cpp">$1</pre>',  
                        //added paragraph  
                        '<p>$1</p>',  
                        );  
          
            // Do simple BBCode's  
            $str = preg_replace ($simple_search, $simple_replace, $str);  
          
            // Do <blockquote> BBCode  
            $str = $this->bbcode_quote ($str);  
         
            return $bbcode;  
        }     

Open in new window


3. in display text in forums it ok, but text not convert \n to <br />

4. i insert code in function.
            $bbcode = nl2br($str);

Open in new window


5. but display in forums in tag [ code ] and show <br />, i not need it
Not work
6. i need u help fix or find function for work bbcode...
0
 
XSoFTzAuthor Commented:
....
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now