Reputation: 2645
I'm attempting to create an SQL filtering system which notifies the user when the request contains any of the included words.
Currently my regex only supports all caps & I was wondering whether it would be possible to have it also accept non-caps as-well as other combinations of letters for example SElEcT
I understand entering this manually would be possible, however, this is not the most productive way to perform such a task.
This is my current code:
function checkString($string)
{
if(preg_match('[SELECT|FROM|DATABASE|TABLE|DROP|ALTER|LIKE|IN|BETWEEN|UNION|NULL|CHECK|JOIN|AVG|SUM|COUNT|FIRST|LAST|MAX|MIN|GROUP]', $string
Thanks.
Upvotes: 2
Views: 425
Reputation: 1647
Use the i
modifier (makes the regex case insensitive.):
if(preg_match('/(SELECT|FROM|DATABASE|TABLE|DROP|ALTER|LIKE|IN|BETWEEN|UNION|NULL|CHECK|JOIN|AVG|SUM|COUNT|FIRST|LAST|MAX|MIN|GROUP)/i', $string
Upvotes: 6