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

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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.