Last active
December 21, 2015 02:09
-
-
Save stavrossk/6232987 to your computer and use it in GitHub Desktop.
PHP Snippet: BBS Code Converter: This script will convert Bulletin Board Code into readable HTML, good for comments, forums, etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 bold text[/b] | |
and this is [color=#FF0000]Red text[/color]'); | |
echo'<br>'; | |
echo text2bbc('this text is italic[/i] and this is not'); | |
echo'<br>'; | |
echo text2bbc('here we have underlined[/u] text'); | |
echo'<br>'; | |
echo text2bbc('this is [size=24]24px[/size] font'); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment