Koden ser nu ut så här (ungefär som tidigare).
- Kod: Markera allt
/**
* Helper, BBCode formatting converting to HTML.
*
* @param string text The text to be converted.
*
* @returns string the formatted text.
*/
function bbcode2html($text) {
$search = [
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[img\](https?.*?)\[\/img\]/is',
'/\[url\](https?.*?)\[\/url\]/is',
'/\[url=(https?.*?)\](.*?)\[\/url\]/is'
];
$replace = [
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<img src="$1" />',
'<a href="$1">$1</a>',
'<a href="$1">$2</a>'
];
return preg_replace($search, $replace, $text);
}