I have a php script validation that looks for some special chars and deletes them. The script works fine but if I put anything between two $ it is deleted as well. So if put in
Supercool$$$$%%email%%@%SP***AM.com; => Supercoolemail@SPAM.com
but if I input
Supercool$$email$$%%@%SP**AM.com => Supercool@SPAM.com
Whenever I put regular chars between $’s they are delete as well. Here is the PHP script that I use to check for special chars in the inputed email:
<?php
$bademail = "MAXCOOL$$ES$$%%T%%@%SP***AM.com";
function specialcharsreg ($email){
$regex = "/[*?$!%$&#]/";
$validemail = preg_replace($regex, "", $email);
echo "\n=====================================\n".$email." -> ".$validemail."\n=====================================\n\n";
}
specialcharsreg($bademail);
?>
The expression does not replace that.
You are just not quoting your string properly and
$variables are getting interpolated.Your (double quotes):
Should be (variables are not interpolated when using single quotes):
Or you can escape the
$s with backslashes: