Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple bbCode [TUT]
#4
Very good tut.
I use this simple function whenever I like to parse the BBcode.
PHP Code:
<?
function bbcode($text){
   
$text str_replace('<''<'$text);
   
$text str_replace('>''>'$text);
   
$text str_replace('"'""", $text);
   
   
$text = str_replace('[b]', '<b>', $text);
   
$text = str_replace('[/b]', '</b>', $text);
   
$text = str_replace('[i]', '<i>', $text);
   
$text = str_replace('[/i]', '</i>', $text);
   
$text = str_replace('[u]', '<u>', $text);
   
$text = str_replace('[/u]', '</u>', $text);
   
$text = str_replace('[url=', '<a href="', $text);
   $text = str_replace('
[/url]', '</a>', $text);
   $text = str_replace('
[img]', '<img src="', $text);
   
$text = str_replace('[/img]', '">', $text);
   $text = str_replace('
[c]', '<center>', $text);
   $text = str_replace('
[/c]', '</center>', $text);
   $text = str_replace('
]', '">', $text);
   
   
$text = str_replace('[B]', '<b>', $text);
   
$text = str_replace('[/B]', '</b>', $text);
   
$text = str_replace('[I]', '<i>', $text);
   
$text = str_replace('[/I]', '</i>', $text);
   
$text = str_replace('[U]', '<u>', $text);
   
$text = str_replace('[/U]', '</u>', $text);
   
$text = str_replace('[URL=', '<a href="', $text);
   $text = str_replace('
[/URL]', '</a>', $text);
   $text = str_replace('
[IMG]', '<img src="', $text);
   
$text = str_replace('[/IMG]', '">', $text);
   $text = str_replace('
[C]', '<center>', $text);
   $text = str_replace('
[/C]', '</center>', $text);
   $text = str_replace('
]', '">', $text);
   
   
$text = nl2br($text);
   
$text = trim($text);
   
   return 
$text;

?>

Hopefully this is also an helpful idea Smile
Reply


Messages In This Thread
Simple bbCode [TUT] - by Gaijin - 10-17-2009, 08:47 AM
RE: Simple bbCode [TUT] - by Viciousness - 10-17-2009, 08:50 AM
RE: Simple bbCode [TUT] - by Gaijin - 10-17-2009, 08:52 AM
RE: Simple bbCode [TUT] - by zone - 11-08-2009, 07:44 PM
RE: Simple bbCode [TUT] - by Gaijin - 11-08-2009, 07:49 PM
RE: Simple bbCode [TUT] - by zone - 11-08-2009, 07:58 PM
RE: Simple bbCode [TUT] - by Gaijin - 11-08-2009, 08:01 PM
RE: Simple bbCode [TUT] - by zone - 11-08-2009, 09:25 PM
RE: Simple bbCode [TUT] - by Bencori - 05-25-2011, 01:32 PM
RE: Simple bbCode [TUT] - by Carbon Host - 08-02-2011, 08:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  BBCode problem Horusbrasil 11 2,016 04-06-2010, 09:57 AM
Last Post: Horusbrasil

Forum Jump:


Users browsing this thread: 1 Guest(s)