How does the strip_tags function in PHP help in sanitizing user input containing HTML tags?

When dealing with user input that may contain HTML tags, it is important to sanitize the input to prevent potential security vulnerabilities such as cross-site scripting (XSS) attacks. The strip_tags function in PHP is a simple and effective way to remove all HTML tags from a string, leaving only the plain text content.

$user_input = "<p>Hello, <script>alert('XSS attack!');</script>World!</p>";
$clean_input = strip_tags($user_input);

echo $clean_input; // Output: Hello, World!