Home / PHP Tips Generated By ChatGPT / Simple User Input Sanitization in PHP Sanitize a string input using filter_var() with FILTER_SANITIZE_STRING. Source Code $userInput = "alert('hack');"; $safeInput = filter_var($userInput, FILTER_SANITIZE_STRING); echo $safeInput;