BigToach.com

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>
?>

Added on Jun 24th at 8 pm by Scott - 0 Comments
Updated on Jun 27th at 3 am.


0 Responses to bbasic

Name:

Site or Mail:

Comment:

To try to reduce the ammount of spam, please enter the word GOOSE in the following form

Security Code: