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 #21

hi I am still facing a problem. and code isn't working even when I use it properly. Hellooooooooo[/b ] it is also showing BB Code Error. what to do? @ s. else.

Wait...

anderson Developer · 146 posts #22

when and code used in a text shows BB Code Error. actually code is correct. its happening only for this 2 codes.

Wait...

something else Fellow · 2,296 posts #23

iv just tested both ways and both are working fine? test file below: test.php

<?php
function checkbbcode($text)
{
$bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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/>");
?>
anderson Developer · 146 posts #24

Problem is solved.

Wait...

something else Fellow · 2,296 posts #25

change this line: $testb = array("","","","[/big]","[/small]"); to $testb = array("","","","[/big]","[/small]");

coding-talk script messed up coding lol

anderson Developer · 146 posts #26

First time coding-talk script make me foolish, also make me lol!! Thanks. working now. ===X===

Wait...

shad0w Developer · 119 posts #27

Or ... you can add this in the begining of getbbcode function:D

$bbcheck=preg_replace("/\[b\](.*?)\[\/b\]/i","", $text);
$testa = array("[b]","[i]","[u]","[big]","[small]");
$testb = array("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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("[/b]","[/i]","[/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; 
}

whatmp3.name - search mp3 on mobile

Write your reply now; next you create a free account (or sign in) and it is posted right away. 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