Re: Better method than stristr
| From: | tedd | Date: | Mon, 29 May 2006 23:54:15 +0000 |
| Subject: | Re: Better method than stristr | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-237049@lists.php.net to get a copy of this message | ||
At 2:27 PM -0500 5/29/06, Steven Osborn wrote:
Can someone please advise a faster solution to do what I'm doing below? All I need to be able to do is determine if any of the strings in the array are contained in $q. The method I have works, but I'm sure its not the most efficient way to do it. $dirtyWord = array("UNION","LOAD_FILE","LOAD DATA INFILE","LOAD FILE","BENCHMARK","INTO OUTFILE"); foreach($dirtyWord as $injection) { if(stristr($q,$injection)) { //Do Something to remove injection and log it } } Thank you. --Steven--Steven: This is the way I would attempt it. $q = explode(" ", $q); $result = array_intersect($dirtyWord,$q); If (count($result)) {
// then you have dirty words} If you want to remove them, then try this: $q = explode(" ", $q); $result = array_diff($dirtyWord,$q); $q = implode(" ", $result); But why are you doing this? hth's tedd -- ------------------------------------------------------------------------------------ http://sperling.com http://ancientstones.com http://earthstones.com