With the deprecation of FILTER_SANITIZE_STRING, the "use htmlspecialchars instead" is an incomplete comment. The functionality of FILTER_SANITIZE_STRING was a combination of htmlspcialchars and (approximately) strip_tags. For true compatibility a polyfil may be needed:
<?php
function filter_string_polyfill(string $string): string
{
$str = preg_replace('/\x00|<[^>]*>?/', '', $string);
return str_replace(["'", '"'], [''', '"'], $str);
}
$string = "Some \"' <bizzare> string & to Sanitize < !$@%";
echo filter_var($string,FILTER_SANITIZE_STRING).PHP_EOL;
echo htmlspecialchars($string).PHP_EOL;
echo strip_tags($string).PHP_EOL;
echo htmlspecialchars(strip_tags($string,ENT_QUOTES)).PHP_EOL;
echo filter_string_polyfill($string).PHP_EOL;