Gestire BBCode in PHP

function BBCode($text) {
/**
* The following array has the structure Key => Value.
* The key is the item that will be typed e.g [b] the value will be the html equivilant.
*/
	$BBCode = array("&" => "&amp;", "< " => "&lt;", ">" => "&gt;", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'/>"); // Comment Above
	$parsedtext = str_replace(array_keys($BBCode), array_values($BBCode), $text); //This function will get the input string. and then the keys and values of the array above. It will then replace them with the html equivilant.
	return $parsedtext; // Return $parsedtext.
}

Esempio Applicato:

$text = BBCode("[b][u]HELLO[/u][/b]"); // Execute Function
echo $text; // Echo $text.

Tratto da http://www.sastgroup.com/tutorials/bbcode-in-php


Pubblicato

in

da