Jump to content

[SOLVED] problems with bbcode function


almightyegg

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.