PHP Snippets
bbasic
Information
(PHP Version >= 3.0.9)Functions used in this snippet: preg_replace.
Description
str bbasic(str string)
Replaces [b],[i], and [type] with bold text, italicized text, and colored text respectively. The Functions returns an adjusted str of the supplied string.
Snippet
<?php
function bbasic($str){
$str = preg_replace('/\[b\](.+?)\[\/b\]/ims','<span class="bold">$1</span>',$str);
$str = preg_replace('/\[i\](.+?)\[\/i\]/ims','<span class="italic">$1</span>',$str);
$str = preg_replace('/\[type\](.+?)\[\/type\]/ims','<span class="type">$1</span>',$str);
return $str;
}
?>
Example
bbasic Can be used in the following way:
<?php
echo bbasic('[b]yay this is bold[b]');
// above text is turned to <span class="bold">yay this is bold</span>
echo bbasic('[type]string[/type] are [i]italic[/i]');
// above text is turned to <span class="type">string</span> are <span class="italic">italic</span>
?>
Updated on Jun 27th at 3 am.
0 Responses to bbasic