Jump to content

[SOLVED] Allow input of html to database


SirChick

Recommended Posts

I was wondering.. say a user wants to bold something in a forum:

 

Some have:

[b]Test[/b]

 

then html uses:

<b>Test</b>

 

Now how do you make it so user input "allows"

[b][/b] 

etc and also means when the text is echo'd it will be

[b]bold[/b]

?

 

Is it all done in html or is php involved too ? Will string escape function disallow it or does it allow it?

Link to comment
https://forums.phpfreaks.com/topic/82991-solved-allow-input-of-html-to-database/
Share on other sites

<?php
function bbcode_format($post)
{

$post = htmlentities($post);

$simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is'
                                );

        $simple_replace = array(
                                '<strong>$1</strong>'
                                );

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

 

<?php
$simple_search = array(
                                '/\[b\](.*?)\[\/b\]/is'
                                );

        $simple_replace = array(
                                '<strong>$1</strong>'
                                );
?>

 

 

Could you explain this part a bit... not sure i follow what thats doing ? Is it like a way to stop injection with bbcode ?

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.