How can HTML code be prevented from functioning in a form input while still allowing BBCode to work?

To prevent HTML code from functioning in a form input while still allowing BBCode to work, you can use the PHP strip_tags() function to remove any HTML tags from the input before displaying it. This will ensure that only BBCode is displayed and any potentially harmful HTML code is removed.

$input = "<b>Hello</b> [b]World[/b]";
$bbcode = strip_tags($input);
echo $bbcode;