I have the following function that is used to take special characters from a string:
function removeSpecialChars($string){
//List (Array) of special chars
$pattern = array("/(á|à|ã|â|ä)/","/(Á|À|Ã|Â|Ä)/","/(é|è|ê|ë)/","/(É|È|Ê|Ë)/","/(í|ì|î|ï)/","/(Í|Ì|Î|Ï)/","/(ó|ò|õ|ô|ö)/","/(Ó|Ò|Õ|Ô|Ö)/","/(ú|ù|û|ü)/","/(Ú|Ù|Û|Ü)/","/(ñ)/","/(Ñ)/","/(ç)/","/(Ç)/","/(\'|\"|\^|\~|\;|\:|\°|\?|\&|\*|\+|\@|\#|\$|\%|\!|\|\/|\(|\)|\||\=|\.|\,)/");
//List (Array) of letters
$replacement = array('a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'n', 'N', 'c', 'C', '');
return preg_replace($pattern , $replacement, $string);
}
It works fine, the only problem is that this function can not replace the forward slash, whether it is inverted ( \
) or normal ( /
), and the dollar sign ( $
), but if I put this regular expression on some website to test, such as I placed that link works normally.
Does anyone know why it does not work in PHP?