Simple BBcode Parse PHP Function

Usage:

echo 'Message:<br />'.parsebb($text);

PHP Function:

function parsebb($body) {
    $find = array(
        "@\n@",
        "@[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]@is", 
        "/\[url\=(.+?)\](.+?)\[\/url\]/is",
        "/\[b\](.+?)\[\/b\]/is", 
        "/\[i\](.+?)\[\/i\]/is", 
        "/\[u\](.+?)\[\/u\]/is", 
        "/\[color\=(.+?)\](.+?)\[\/color\]/is",
        "/\[size\=(.+?)\](.+?)\[\/size\]/is", 
        "/\[font\=(.+?)\](.+?)\[\/font\]/is",
        "/\[center\](.+?)\[\/center\]/is",
        "/\[right\](.+?)\[\/right\]/is",
        "/\[left\](.+?)\[\/left\]/is",
        "/\[img\](.+?)\[\/img\]/is",
        "/\[email\](.+?)\[\/email\]/is"
    );
    $replace = array(
        "<br />",
        "<a href=\"\\0\">\\0</a>",
        "<a href=\"$1\" target=\"_blank\">$2</a>",
        "<strong>$1</strong>",
        "<em>$1</em>",
        "<span style=\"text-decoration:underline;\">$1</span>",
        "<font color=\"$1\">$2</font>",
        "<font size=\"$1\">$2</font>",
        "<span style=\"font-family: $1\">$2</span>",
        "<div style=\"text-align:center;\">$1</div>",
        "<div style=\"text-align:right;\">$1</div>",
        "<div style=\"text-align:left;\">$1</div>",
        "<img src=\"$1\" alt=\"Image\" />",
        "<a href=\"mailto:$1\" target=\"_blank\">$1</a>"
    );
    $body = htmlspecialchars($body);
    $body = preg_replace($find, $replace, $body);
    return $body;
}

 

How to choose a random word from an array php
<?php $Words =array("Black","Yellow","Blue","Red","Purple","Pink", "White"); $rand_word=array_rand($Words,2); $Result =
How to minify HTML code of PHP page
<?php ob_start("minifier"); function minifier($code) { $search =
How to copy a file from one directory to another using PHP
<?php // Copy the file from /user/desktop/geek.txt
How to Deleting all files from a folder using PHP
<?php // PHP program to delete all
How do I test if an remote image file exists in php
if(@get_headers($your_url) == 'HTTP/1.1 404 Not Found') {
Human Readable File Size with PHP
function bytesToHuman($bytes) { $units = ['B', 'KB',
PHP Simple File Upload from Remote URL
<?php if($_POST){ //get the url $url =
PHP unzipper / extracts .zip archives and .gz files on webservers
<?php $timestart = microtime(TRUE); $arc = new
Get the first character in a string with PHP
//Example string. $string = "My milkshake brings
How to generate a random token with PHP
//Generate a random string. $token = openssl_random_pseudo_bytes(16);
How to handle HTML checkboxes with PHP
<?php //Set "terms accepted" to false by
Generating random names with PHP
<?php //PHP array containing forenames. $names =
How to create PHP Timer Countdown
//You must call the function session_start() before
PHP – Do not echo out HTML!
Wrong: <?php echo '<div id="user_profile">'; echo '<h1>'
How to rotate a series of words on page load using PHP
$words = array('fox', 'hippo', 'dog', 'cat'); echo
How to check if a value exists in an array in PHP
$zoo = array("Lion", "Elephant", "Tiger", "Zebra", "Rhino",
How to Get the Current Date and Time in PHP
date_default_timezone_set('Asia/Kolkata'); $date = date('d-m-y h:i:s'); echo $date;
How to remove HTML special characters from a string in PHP
$my_str = "String with <b>special</b> characters."; //
How to extract substring from a string in PHP
$str = "Hello World!"; echo substr($str, 0,

Top