# front-end-pm/1.3/bbcode.php

Front End PM, version 1.3. 62 lines.

- Page: https://pluginprobe.com/plugins/front-end-pm/1.3/code/bbcode.php
- Raw: https://pluginprobe.com/plugins/front-end-pm/1.3/raw/bbcode.php
- Modified: 2014-06-09T17:49:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/front-end-pm/1.3/code/bbcode.php#L10-L20`.

```php
<?php
/*
* Class for parsing BBCode
* @author	Shamim, http://www.banglardokan.com/blog/recent/project/front-end-pm-2215/
*Ui = 1 line
*Uis = Multiple Lines
*/
class fepBBCParser {
	
	var $patterns = array
	(
		'/\[list\](.+)\[\/list\]/Uis',
		'/\[\*\](.+)\\n/Ui',
		'/\[b\](.+)\[\/b\]/Uis',
		'/\[i\](.+)\[\/i\]/Uis',
		'/\[u\](.+)\[\/u\]/Uis',
		'/\[s\](.+)\[\/s\]/Uis',
		'/\[url=(.+)\](.+)\[\/url\]/Ui',
		'/\[url](.+)\[\/url\]/Ui',
		'/\[email](.+)\[\/email\]/Ui',
		'/\[email=(.+)\](.+)\[\/email\]/Ui',
		'/\[img\](.+)\[\/img\]/Ui',
		'/\[img=(.+)\](.+)\[\/img\]/Ui',
		'/\[code\](.+)\[\/code\]/Uis',
		'/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Ui',
		'/\[color=(\#[0-9a-f]{6}|[a-z]+)\](.+)\[\/color\]/Uis',
		'/\[embed](.+)\[\/embed\]/Ui'
	);
	
	var $replacements = array
	(
		'<ul>\1</ul>',
		'<li>\1</li>',
		'<b>\1</b>',
		'<i>\1</i>',
		'<u>\1</u>',
		'<s>\1</s>',
		'<a href = "\1" target = "_blank">\2</a>',
		'<a href = "\1" target = "_blank">\1</a>',
		'<a href = "mailto:\1">\1</a>',
		'<a href = "mailto:\1">\2</a>',
		'<img src = "\1" alt = "Image" />',
		'<img src = "\1" alt = "\2" />',
		'<pre class = "code">\1</pre>',
		'<span style = "color: \1;">\2</span>',
		'<div style = "color: \1;">\2</div>',
		'\1'
	);
	
	function bbc2html($subject)
	{
		//$subject = nl2br($subject); //UCOMMENT THIS LINE TO REPLACE \n's with <br />'s
		$subject = preg_replace($this->patterns, $this->replacements, $subject);
		
		$findQ = array("[quote]", "[/quote]", "[QUOTE]", "[/QUOTE]");
		$replaceQ  = array("<blockquote>", "</blockquote>", "<blockquote>", "</blockquote>");
		$subjectTwo = str_replace($findQ, $replaceQ, $subject);
		
		return $subjectTwo;
	}
}
?>
```
