Michdd Posted July 19, 2009 Share Posted July 19, 2009 I have a file of disallowed words, and disallowed regular expressions. Each one on a new line, so I know I can get that into an array just doing like explode("\n", $filecontents); But my question is how would I loop through all those to make sure they're not in the content I want to search? Strpos doesn't take arrays, and wouldn't looping through upwards of over a thousand different things be slow? Additionally, how could I check to see if it's a regular expression? And if it is, use preg_match instead? Say I have this: resourcez.com ecspace.us photoangels /a[^a-z0-9]*n[^a-z0-9]*o[^a-z0-9]*n[^a-z0-9]*t[^a-z0-9]*a[^a-z0-9]*l[^a-z0-9]*k[^a-z0-9]*/i And I want to make sure a string doesn't contain either of the first 3, nor the regex expression. Of course, the actual list is way longer. Quote Link to comment https://forums.phpfreaks.com/topic/166472-checking-a-string/ Share on other sites More sharing options...
ignace Posted July 19, 2009 Share Posted July 19, 2009 so I know I can get that into an array just doing like explode("\n", $filecontents); use file() instead. (http://be.php.net/manual/en/function.file.php) Additionally, how could I check to see if it's a regular expression? And if it is, use preg_match instead? Check for special characters like [, *, .. However a better choice would be naming the different types you have within the document and assign each one some signature to clearly identify each type. u;resourcez.com n;photoangels r;/a[^a-z0-9]*n[^a-z0-9]*o[^a-z0-9]*n[^a-z0-9]*t[^a-z0-9]*a[^a-z0-9]*l[^a-z0-9]*k[^a-z0-9]*/i Now it allows you to expand it in the future with new types plus it allows you to easily identify each line. switch ($type) { case 'u': //logic break; case 'n': //logic break; case 'r': //logic break; } Quote Link to comment https://forums.phpfreaks.com/topic/166472-checking-a-string/#findComment-877945 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.