What are potential pitfalls of using strip_tags() in PHP for user input sanitization?

Using strip_tags() for user input sanitization can potentially lead to security vulnerabilities as it only removes HTML tags and does not handle other potentially harmful content like JavaScript or CSS. To address this, it is recommended to use a more comprehensive sanitization approach such as using filter_var() with FILTER_SANITIZE_STRING or a dedicated library like HTML Purifier.

// Using filter_var() with FILTER_SANITIZE_STRING for more comprehensive sanitization
$user_input = "<script>alert('XSS attack!')</script>";
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);
echo $sanitized_input;