| 1 |
<?php |
| 2 |
/* |
| 3 |
* Class for parsing BBCode |
| 4 |
* @author Shamim, http://www.banglardokan.com/blog/recent/project/front-end-pm-2215/ |
| 5 |
*Ui = 1 line |
| 6 |
*Uis = Multiple Lines |
| 7 |
*/ |
| 8 |
class fepBBCParser { |
| 9 |
|
| 10 |
var $patterns = array |
| 11 |
( |
| 12 |
'/\[list\](.+)\[\/list\]/Uis', |
| 13 |
'/\[\*\](.+)\\n/Ui', |
| 14 |
'/\[b\](.+)\[\/b\]/Uis', |
| 15 |
'/\[i\](.+)\[\/i\]/Uis', |
| 16 |
'/\[u\](.+)\[\/u\]/Uis', |
| 17 |
'/\[s\](.+)\[\/s\]/Uis', |
| 18 |
'/\[url=(.+)\](.+)\[\/url\]/Ui', |
| 19 |
'/\[url](.+)\[\/url\]/Ui', |
| 20 |
'/\[email](.+)\[\/email\]/Ui', |
| 21 |
'/\[email=(.+)\](.+)\[\/email\]/Ui', |
| 22 |
'/\[img\](.+)\[\/img\]/Ui', |
| 23 |
'/\[img=(.+)\](.+)\[\/img\]/Ui', |
| 24 |
'/\[code\](.+)\[\/code\]/Uis', |
| 25 |
'/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Ui', |
| 26 |
'/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Uis', |
| 27 |
'/\[embed](.+)\[\/embed\]/Ui' |
| 28 |
); |
| 29 |
|
| 30 |
var $replacements = array |
| 31 |
( |
| 32 |
'<ul>\1</ul>', |
| 33 |
'<li>\1</li>', |
| 34 |
'<b>\1</b>', |
| 35 |
'<i>\1</i>', |
| 36 |
'<u>\1</u>', |
| 37 |
'<s>\1</s>', |
| 38 |
'<a href = "\1" target = "_blank">\2</a>', |
| 39 |
'<a href = "\1" target = "_blank">\1</a>', |
| 40 |
'<a href = "mailto:\1">\1</a>', |
| 41 |
'<a href = "mailto:\1">\2</a>', |
| 42 |
'<img src = "\1" alt = "Image" />', |
| 43 |
'<img src = "\1" alt = "\2" />', |
| 44 |
'<pre class = "code">\1</pre>', |
| 45 |
'<span style = "color: \1;">\2</span>', |
| 46 |
'<div style = "color: \1;">\2</div>', |
| 47 |
'\1' |
| 48 |
); |
| 49 |
|
| 50 |
function bbc2html($subject) |
| 51 |
{ |
| 52 |
//$subject = nl2br($subject); //UCOMMENT THIS LINE TO REPLACE \n's with <br />'s |
| 53 |
$subject = preg_replace($this->patterns, $this->replacements, $subject); |
| 54 |
|
| 55 |
$findQ = array("[quote]", "[/quote]", "[QUOTE]", "[/QUOTE]"); |
| 56 |
$replaceQ = array("<blockquote>", "</blockquote>", "<blockquote>", "</blockquote>"); |
| 57 |
$subjectTwo = str_replace($findQ, $replaceQ, $subject); |
| 58 |
|
| 59 |
return $subjectTwo; |
| 60 |
} |
| 61 |
} |
| 62 |
?> |