What functions or methods in PHP can be used to sanitize user input on a forum board?

When dealing with user input on a forum board, it is important to sanitize the data to prevent malicious code injection or other security vulnerabilities. One way to sanitize user input in PHP is by using the filter_var() function with the FILTER_SANITIZE_STRING flag to remove any potentially harmful characters. Additionally, you can use htmlentities() function to convert special characters to HTML entities, further securing the input.

// Sanitize user input on a forum board
$user_input = $_POST['user_input'];

// Sanitize user input using filter_var() function
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);

// Convert special characters to HTML entities
$sanitized_input = htmlentities($sanitized_input);

// Now $sanitized_input is safe to use in your forum board