Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/166472-checking-a-string/
Share on other sites

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;
}

Link to comment
https://forums.phpfreaks.com/topic/166472-checking-a-string/#findComment-877945
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.