Originally posted by something else
View Post
How to prevent BBCodes error from shoutbox
Collapse
X
-
this should work now:
PHP Code: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;
}
Comment
-
iv just tested both ways and both are working fine?
test file below:
test.php
PHP Code:<?php
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);
echo "1) $bbcheck<br/>";
$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*");
echo "3) $checkb<br/>";
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;
}
echo checkbbcode("[b]hello[/b]<br/>");
echo checkbbcode("[b][i]hello[/i][/b]<br/>");
?>
Comment
-
Or ... you can add this in the begining of getbbcode function:D
PHP Code:$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 = "BBCODE ERROR!!!";
return $text;
}
$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 = "BBCODE ERROR!!!";
return $text;
}
$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 = "BBCODE ERROR!!!";
return $text;
}
$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 = "BBCODE ERROR!!!";
return $text;
}
$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 = "BBCODE ERROR!!!";
return $text;
}
Last edited by shad0w; 29.12.09, 01:54.whatmp3.name - search mp3 on mobile
Comment
Comment