(I am new to stackoverflow, so I am doing the wrong way / doing poor work using the style of my answer, feel free to tell me.)
Correct me if I am wrong, as I am also dealing with the same problem right now, but I don’t think that the accepted answer using filter_var is enough, as attackers can work around this with Unicode.
Example: "& # 66; & # 99; & # 99; & # 58;" (spaces are added, so stackoverflow will display them correctly)
This will not be removed from the string and will later be replaced with "Bcc:".
This is my decision, but there may be a better way. If anyone knows one thing, I would like to hear it.
$string = str_replace("&", "(and)", $string); $string = str_replace("#", "(num)", $string); $string = str_replace(";", "(semi-colon)", $string); $string = str_replace(":", "(colon)", $string); $string = str_replace("@", "(at)", $string); $string = str_replace("\\", "(backslash)", $string); $string = filter_var($string, FILTER_SANITIZE_STRING);
Mason
source share