Jump to content

Recommended Posts

I decided to add a language filter to my BBcodes function

 

I used a test post yet it seemed the words appeared normally (I have filled the words with ---- for uses on tis board)

function bbcode_format($post) {
$post = htmlentities($post);

$simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is',                                
                                '/\[i\](.*?)\[\/i\]/is',                                
                                '/\[u\](.*?)\[\/u\]/is',
                                '/\[center\](.*?)\[\/center\]/is',
                                '/\[right\](.*?)\[\/right\]/is',
			'/\[img=(.*?)\]/is',
			'/\[(.*?)\](.*?)\[\/url]/is',
			'/\[colour=(.*?)\](.*?)\[\/colour]/is',
			'/\[quote\](.*?)\[\/quote]/is',
			'/\[br]/is',
			'/\[hr]/is',
			'/\[h1](.*?)\[\/h1\]/is',
			'/\[h2](.*?)\[\/h2\]/is',
			'/\[h3](.*?)\[\/h3\]/is',
			'/\----/is',
			'/\----/is',
			'/\----/is',
			'/\----/is'
                                );

        $simple_replace = array(
                                '<strong>$1</strong>',
                                '<em>$1</em>',
                                '<u>$1</u>',
                                '<center>$1</center>',
                                '<right>$1</right>',
			'<img src="$1">',
			'<a href="$1">$2</a>',
			'<font color=$1>$2</font>',
			'<br><table border=0 bgcolor=#000000><td>$1</td></table><br>',
			'<br>',
			'<hr>',
			'<h1>$1</h1>',
			'<h2>$1</h2>',
			'<h3>$1</h3>',
			'f***',
			's***',
			't***',
			'c***'
                                );

        // Do simple BBCode's
        $post = preg_replace ($simple_search, $simple_replace, $post);


        
        return $post;
}

Link to comment
https://forums.phpfreaks.com/topic/69360-solved-problems-with-bbcode-function/
Share on other sites

It works!

 

<?php
function bbcode_format($post)
{

$post = htmlentities($post);

$simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is',                                
                                '/\[i\](.*?)\[\/i\]/is',                                
                                '/\[u\](.*?)\[\/u\]/is',
                                '/\[center\](.*?)\[\/center\]/is',
                                '/\[right\](.*?)\[\/right\]/is',
			'/\[img=(.*?)\]/is',
			'/\[(.*?)\](.*?)\[\/url]/is',
			'/\[colour=(.*?)\](.*?)\[\/colour]/is',
			'/\[quote\](.*?)\[\/quote]/is',
			'/\[br]/is',
			'/\[hr]/is',
			'/\[h1](.*?)\[\/h1\]/is',
			'/\[h2](.*?)\[\/h2\]/is',
			'/\[h3](.*?)\[\/h3\]/is',
			'/\----/is',
			'/\----/is',
			'/\----/is',
			'/\----/is'
                                );

        $simple_replace = array(
                                '<strong>$1</strong>',
                                '<em>$1</em>',
                                '<u>$1</u>',
                                '<center>$1</center>',
                                '<right>$1</right>',
			'<img src="$1">',
			'<a href="$1">$2</a>',
			'<font color=$1>$2</font>',
			'<br><table border=0 bgcolor=#000000><td>$1</td></table><br>',
			'<br>',
			'<hr>',
			'<h1>$1</h1>',
			'<h2>$1</h2>',
			'<h3>$1</h3>',
			'f***',
			's***',
			't***',
			'c***'
                                );

        // Do simple BBCode's
        $post = preg_replace ($simple_search, $simple_replace, $post);

        return $post;
}

$post = "[b]hello[/b]";
$p = bbcode_format($post);

echo $post."<br>";
echo $p."<br>";
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.