How to prevent BBCodes error from shoutbox

Started on the old forum in September 2009 · view the original in the archive · old links redirect here

26 replies · 1,052 views · started 17 years ago · 1 min read

6 participants
anderson Developer · 146 posts #1

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:

[b ][i ] [u ]some text[/u ][/b ][/i ]

but it should be:

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

johnny Junior · 47 posts #2

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

Learner lolz

anderson Developer · 146 posts #3

johnny wrote: 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...

kuklux Newbie · 8 posts #4

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

anderson Developer · 146 posts #5

kuklux wrote: 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...

ori Lead · 512 posts #6

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

anderson Developer · 146 posts #7

ori wrote: if there in wrong order i would think they would just see the txt of the code 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...

something else Fellow · 2,296 posts #8

Soloution

anderson wrote: 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:

[b ][i ] [u ]some text[/u ][/b ][/i ]

but it should be:

[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

$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 8)

anderson Developer · 146 posts #9

something else wrote: I havent tested this and there is probably a better way to code this but heres a code iv made to stop it

$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 8)

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:

$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:

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

something else Fellow · 2,296 posts #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)

anderson Developer · 146 posts #11

something else wrote: 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:

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:

$text = checkbbcode(getbbcode($text, $sid));

?? but how it will work! ❗

Wait...

something else Fellow · 2,296 posts #12
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); }

anderson Developer · 146 posts #14

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

I think str_replace is needed that can change bib2 to

Wait...

something else Fellow · 2,296 posts #15

oops yeah sorry it needs to be:

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

anderson Developer · 146 posts #16

something else wrote: oops yeah sorry it needs to be:

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

Sorry to say, did accordingly but not working. Still error in page!!!

Wait...

something else Fellow · 2,296 posts #17

this should work now:

function checkbbcode($text)
{
$bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/u][/i][/b][i][u]","[/u][/i][u]","[/u]","[/big]","[/small]");
$testa = str_replace($testa, "*bb1*", $bbcheck);
$testb = str_replace($testb, "*bb2*", $bbcheck);
$checka = substr_count($testa,"*bb1*");
$checkb = substr_count($testb,"*bb2*");
if($checka!=$checkb){
$text = "BB Code Error";
}
$bbcheck=preg_replace("/\[i\](.*?)\[\/i\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/u][/i][/b][i][u]","[/u][/i][u]","[/u]","[/big]","[/small]");
$testa = str_replace($testa, "*bb1*", $bbcheck);
$testb = str_replace($testb, "*bb2*", $bbcheck);
$checka = substr_count($testa,"*bb1*");
$checkb = substr_count($testb,"*bb2*");
if($checka!=$checkb){
$text = "BB Code Error";
}
$bbcheck=preg_replace("/\[u\](.*?)\[\/u\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/u][/i][/b][i][u]","[/u][/i][u]","[/u]","[/big]","[/small]");
$testa = str_replace($testa, "*bb1*", $bbcheck);
$testb = str_replace($testb, "*bb2*", $bbcheck);
$checka = substr_count($testa,"*bb1*");
$checkb = substr_count($testb,"*bb2*");
if($checka!=$checkb){
$text = "BB Code Error";
}
$bbcheck=preg_replace("/\[big\](.*?)\[\/big\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/u][/i][/b][i][u]","[/u][/i][u]","[/u]","[/big]","[/small]");
$testa = str_replace($testa, "*bb1*", $bbcheck);
$testb = str_replace($testb, "*bb2*", $bbcheck);
$checka = substr_count($testa,"*bb1*");
$checkb = substr_count($testb,"*bb2*");
if($checka!=$checkb){
$text = "BB Code Error";
}
$bbcheck=preg_replace("/\[small\](.*?)\[\/small\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/u][/i][/b][i][u]","[/u][/i][u]","[/u]","[/big]","[/small]");
$testa = str_replace($testa, "*bb1*", $bbcheck);
$testb = str_replace($testb, "*bb2*", $bbcheck);
$checka = substr_count($testa,"*bb1*");
$checkb = substr_count($testb,"*bb2*");
if($checka!=$checkb){
$text = "BB Code Error";
}
return $text; 
}
anderson Developer · 146 posts #18

yes. something else! it's working!!! And I cant help thanking you!

Wait...

anderson Developer · 146 posts #19

and can I use this code in genproc.php like if(!checkbbcode($shtxt) { do shout }else{ bbcode error} or how?

Wait...

something else Fellow · 2,296 posts #20

just add it in your parsepm fuction in core.php but make sure it is before : $text = getbbcode($text,$sid); that way it will cover whole of forum and chat

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close