How can developers allow certain HTML tags or BB codes in form inputs while still ensuring security in PHP?

Developers can use functions like `strip_tags()` or `htmlspecialchars()` in PHP to allow only certain HTML tags or BB codes in form inputs while still ensuring security. By using these functions, developers can strip out any potentially harmful code while still allowing safe tags to be displayed.

// Example code snippet to allow certain HTML tags in form inputs
$input = "<p><strong>Hello</strong></p><script>alert('XSS');</script>";
$allowed_tags = '<p><strong>'; // Define the allowed HTML tags

// Strip out any tags that are not in the allowed list
$clean_input = strip_tags($input, $allowed_tags);

echo $clean_input; // Output: <p><strong>Hello</strong></p>