How to prevent BBCodes error from shoutbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to prevent BBCodes error from shoutbox

    hello,
    Sometimes I face this problem in my WML site that when someone does a mistake in bbcode sequence in shoutbox the homepage then doesnt open. as example sometimes they apply like this:
    Code:
    [b ][i ] [u ]some text[/u ][/b ][/i ]
    but it should be:
    Code:
    [b ][i ] [u ]some text[/u ][/i ][/b ]
    As a result users having WAP 1.0 browser arent able to enter homepage. Whenever the shout is deleted they can come.

    If anyone has its solution sothat after applying errors the page still can open plz share here.
    Wait...
    sigpic

    #2
    its simple buddy just dont use so many bbc codes in shoutbox

    Comment


      #3
      Originally posted by johnny View Post
      its simple buddy just dont use so many bbc codes in shoutbox
      Noh johnnoy! I dont like ur solution. I am thinking on such a function that always check if bbcode sequence correct.
      Wait...
      sigpic

      Comment


        #4
        Then add this [b ][i ] [u ] in ur bbcodes so u wont get error! Tnt

        Comment


          #5
          Originally posted by kuklux View Post
          Then add this [b ][i ] [u ] in ur bbcodes so u wont get error! Tnt
          It would make me happy if anyone doesn't post useless n foolish post.
          Wait...
          sigpic

          Comment


            #6
            if there in wrong order i would think they would just see the txt of the code [/b] etc as it looks for start and end before it gets processed if it dont do that show me ur bbcode function

            Comment


              #7
              Originally posted by ori View Post
              if there in wrong order i would think they would just see the txt of the code [/b] etc as it looks for start and end before it gets processed if it dont do that show me ur bbcode function
              I have general lavalair wml bbcode system. but when a user does a mistake in ending the code with proper sequence then it occurs a problem for WAP 1.0 mobile browser. Then these browsers cant open homepage. I am just loking for a function that can ensure users to end up bbcode corrently. if they they mistake it will show "Wrong BBCode Sequence" or something like that.

              Do u have idea?
              Wait...
              sigpic

              Comment


                #8
                Soloution

                Originally posted by anderson View Post
                hello,
                Sometimes I face this problem in my WML site that when someone does a mistake in bbcode sequence in shoutbox the homepage then doesnt open. as example sometimes they apply like this:
                Code:
                [b ][i ] [u ]some text[/u ][/b ][/i ]
                but it should be:
                Code:
                [b ][i ] [u ]some text[/u ][/i ][/b ]
                As a result users having WAP 1.0 browser arent able to enter homepage. Whenever the shout is deleted they can come.

                If anyone has its solution sothat after applying errors the page still can open plz share here.
                I havent tested this and there is probably a better way to code this but heres a code iv made to stop it
                Code:
                $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $text);
                $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                $testa = array("b1","i1","u1","big1","small1");
                $checka = substr_count($bbcheck,$testa);
                $testb = array("b2","i2","u2","big2","small2");
                $checkb = substr_count($bbcheck,$testb);
                if($checka!=$checkb){
                $text = "BB Code Error";
                }
                $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $text);
                $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                $testa = array("b1","i1","u1","big1","small1");
                $checka = substr_count($bbcheck,$testa);
                $testb = array("b2","i2","u2","big2","small2");
                $checkb = substr_count($bbcheck,$testb);
                if($checka!=$checkb){
                $text = "BB Code Error";
                }
                $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $text);
                $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                $testa = array("b1","i1","u1","big1","small1");
                $checka = substr_count($bbcheck,$testa);
                $testb = array("b2","i2","u2","big2","small2");
                $checkb = substr_count($bbcheck,$testb);
                if($checka!=$checkb){
                $text = "BB Code Error";
                }
                $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $text);
                $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                $testa = array("b1","i1","u1","big1","small1");
                $checka = substr_count($bbcheck,$testa);
                $testb = array("b2","i2","u2","big2","small2");
                $checkb = substr_count($bbcheck,$testb);
                if($checka!=$checkb){
                $text = "BB Code Error";
                }
                $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $text);
                $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                $testa = array("b1","i1","u1","big1","small1");
                $checka = substr_count($bbcheck,$testa);
                $testb = array("b2","i2","u2","big2","small2");
                $checkb = substr_count($bbcheck,$testb);
                if($checka!=$checkb){
                $text = "BB Code Error";
                }
                hope this helps
                Last edited by something else; 10.09.09, 10:06.

                Comment


                  #9
                  Originally posted by something else View Post
                  I havent tested this and there is probably a better way to code this but heres a code iv made to stop it
                  Code:
                  $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $text);
                  $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                  $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                  $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                  $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                  $testa = array("b1","i1","u1","big1","small1");
                  $checka = substr_count($bbcheck,$testa);
                  $testb = array("b2","i2","u2","big2","small2");
                  $checkb = substr_count($bbcheck,$testb);
                  if($checka!=$checkb){
                  $text = "BB Code Error";
                  }
                  $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $text);
                  $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                  $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                  $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                  $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                  $testa = array("b1","i1","u1","big1","small1");
                  $checka = substr_count($bbcheck,$testa);
                  $testb = array("b2","i2","u2","big2","small2");
                  $checkb = substr_count($bbcheck,$testb);
                  if($checka!=$checkb){
                  $text = "BB Code Error";
                  }
                  $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $text);
                  $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                  $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                  $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                  $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                  $testa = array("b1","i1","u1","big1","small1");
                  $checka = substr_count($bbcheck,$testa);
                  $testb = array("b2","i2","u2","big2","small2");
                  $checkb = substr_count($bbcheck,$testb);
                  if($checka!=$checkb){
                  $text = "BB Code Error";
                  }
                  $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $text);
                  $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                  $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                  $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                  $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                  $testa = array("b1","i1","u1","big1","small1");
                  $checka = substr_count($bbcheck,$testa);
                  $testb = array("b2","i2","u2","big2","small2");
                  $checkb = substr_count($bbcheck,$testb);
                  if($checka!=$checkb){
                  $text = "BB Code Error";
                  }
                  $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $text);
                  $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                  $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                  $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                  $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                  $testa = array("b1","i1","u1","big1","small1");
                  $checka = substr_count($bbcheck,$testa);
                  $testb = array("b2","i2","u2","big2","small2");
                  $checkb = substr_count($bbcheck,$testb);
                  if($checka!=$checkb){
                  $text = "BB Code Error";
                  }
                  hope this helps
                  Yes! I was searching for a function like this. I will test it. You apply the function 5 times here but we have to apply it more in different sequences.

                  Today I was also thinking to make its function like this:
                  Code:
                  $shtxt = $_POST['shtxt'];
                  now it needs to collect bbcode from the shout text by substr_count() function and explode the shout text by explode function.
                  If substr count gets any bbcode string then it will check like this:
                  Code:
                  $l = [small][u ][i ];
                  $r = [/i ][/u ][/small];
                  if($l==$r)
                    shout true
                  else
                    shout false
                  But it's incomplete. I couldn't think more but your code is better but it need to test. @ something else
                  Wait...
                  sigpic

                  Comment


                    #10
                    you only need to apply it 5 times for thoose 5 bb codes if you do it the way i posted it above it also will cover multiple bb codes as posted above

                    .... if u were to code it the way you have posted you would end up with so many different combination`s (more than 5)

                    Comment


                      #11
                      Originally posted by something else View Post
                      you only need to apply it 5 times for thoose 5 bb codes if you do it the way i posted it above it also will cover multiple bb codes as posted above

                      .... if u were to code it the way you have posted you would end up with so many different combination`s (more than 5)
                      Okay. I am applying ur codes but dont know how to process. Should I creat another function like:
                      Code:
                      function checkbbcode($text)
                      {
                      $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $text);
                      $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                      $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                      $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                      $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                      $testa = array("b1","i1","u1","big1","small1");
                      $checka = substr_count($bbcheck,$testa);
                      $testb = array("b2","i2","u2","big2","small2");
                      $checkb = substr_count($bbcheck,$testb);
                      if($checka!=$checkb){
                      $text = "BB Code Error";
                      return $text;
                      }
                      ..............
                      ............
                      And parse the shout text like:
                      Code:
                      $text = checkbbcode(getbbcode($text, $sid));
                      ?? but how it will work!
                      Last edited by anderson; 11.09.09, 10:55. Reason: more
                      Wait...
                      sigpic

                      Comment


                        #12
                        Code:
                        function checkbbcode($text)
                        {
                        $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $text);
                        $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                        $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                        $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                        $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                        $testa = array("b1","i1","u1","big1","small1");
                        $checka = substr_count($bbcheck,$testa);
                        $testb = array("b2","i2","u2","big2","small2");
                        $checkb = substr_count($bbcheck,$testb);
                        if($checka!=$checkb){
                        $text = "BB Code Error";
                        }
                        $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $text);
                        $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                        $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                        $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                        $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                        $testa = array("b1","i1","u1","big1","small1");
                        $checka = substr_count($bbcheck,$testa);
                        $testb = array("b2","i2","u2","big2","small2");
                        $checkb = substr_count($bbcheck,$testb);
                        if($checka!=$checkb){
                        $text = "BB Code Error";
                        }
                        $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $text);
                        $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                        $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                        $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                        $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                        $testa = array("b1","i1","u1","big1","small1");
                        $checka = substr_count($bbcheck,$testa);
                        $testb = array("b2","i2","u2","big2","small2");
                        $checkb = substr_count($bbcheck,$testb);
                        if($checka!=$checkb){
                        $text = "BB Code Error";
                        }
                        $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $text);
                        $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                        $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                        $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                        $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $bbcheck);
                        $testa = array("b1","i1","u1","big1","small1");
                        $checka = substr_count($bbcheck,$testa);
                        $testb = array("b2","i2","u2","big2","small2");
                        $checkb = substr_count($bbcheck,$testb);
                        if($checka!=$checkb){
                        $text = "BB Code Error";
                        }
                        $bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","small1small2", $text);
                        $bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","big1big2", $bbcheck);
                        $bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","u1u2", $bbcheck);
                        $bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","i1i2", $bbcheck);
                        $bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","b1b2", $bbcheck);
                        $testa = array("b1","i1","u1","big1","small1");
                        $checka = substr_count($bbcheck,$testa);
                        $testb = array("b2","i2","u2","big2","small2");
                        $checkb = substr_count($bbcheck,$testb);
                        if($checka!=$checkb){
                        $text = "BB Code Error";
                        }
                        return $text; 
                        }
                        function parsepm($text,$sid){
                        $text=getbbcode($text,$sid):
                        $text = checkbbcode($text);
                        }
                        Last edited by something else; 11.09.09, 08:24.

                        Comment


                          #13
                          to much to explain lol

                          Comment


                            #14
                            But how it works? because in the function bbcoode is not defined with
                            <b > n </b > for [b ] n [/b ].

                            I think str_replace is needed that can change bib2 to <b > </b >
                            Wait...
                            sigpic

                            Comment


                              #15
                              oops yeah sorry it needs to be:

                              function parsepm($text,$sid){
                              $text = checkbbcode($text);
                              $text=getbbcode($text,$sid):
                              }

                              Comment

                              Working...
                              X