sanitize php strings

Simple function to help you sanitizing the php string. This function will remove any non alphanumeric character.

1
2
3
4
function sanitize($string)
{
   return preg_replace("/[^[:alnum:]]/ui", '', $string);
}

example:

1
2
echo sanitize('café'); /* => café <em>/
echo sanitize('&#124;c/(!=)a f é'); /</em> => café */