I’m trying to remove forbidden chars from a string.
$forbidden = array( "<", ">", "{", "}", "[", "]", "(", ")", "select", "update", "delete", "insert", "drop", "concat", "script");
foreach ($forbidden as $forbidChar) {
if (preg_match("/$forbidChar/i", $string)) {
return TRUE;
}
return FALSE;
}
But it’s not working as expected, where did I go wrong?
You can do this with a single regex like this:
This properly escapes all of the characters with
preg_quote(), and forms a single regex to test for all of the cases.Note: I haven’t tested it, but it should work.