Logo
Bulletin Board Code (BBC)
Online Now: 2
Snippet Code
This will convert Bulletin Board Code into readable HTML, good for comments, forums, etc.
<?php
function text2bbc($text){
    
$find = array(
        
'~\[b\](.*?)\[/b\]~s',
        
'~\[i\](.*?)\[/i\]~s',
        
'~\[u\](.*?)\[/u\]~s',
        
'~\[size=(.*?)\](.*?)\[/size\]~s',
        
'~\[color=(.*?)\](.*?)\[/color\]~s'
    
);
    
$replace = array(
        
'<b>$1</b>',
        
'<i>$1</i>',
        
'<span style="text-decoration:underline;">$1</span>',
        
'<span style="font-size:$1px;">$2</span>',
        
'<span style="color:$1;">$2</span>'
    
);
    return 
preg_replace($find,$replace,$text);
}

echo 
text2bbc('this is some [b]bold text[/b] and this is [color=#FF0000]Red text[/color]');
echo
'<br>';
echo 
text2bbc('this text is [i]italic[/i] and this is not');
echo
'<br>';
echo 
text2bbc('here we have [u]underlined[/u] text');
echo
'<br>';
echo 
text2bbc('this is [size=24]24px[/size] font');
?>
 
Snippet Comments

Add Your Comment

php scripts
2010-09-14 00:32:31
SO easy a BB code. but that is the basic of the complex one. thank you buddy.
CasTex
2009-11-23 00:00:00
That worked on me.
Sam Yong
2009-07-25 00:00:00
@Strefrextor - which part? as of what I know, shouldn't it be \\2 instead of $2?
Strefrextor
2008-08-27 00:00:00
this code is broken

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Professional
Current Score: 2.89
Total votes: 221
Total Views: 10618

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative