Jump to content

Searching for usernames.


Zugzwangle

Recommended Posts

I have a php array called $username_arr, of usernames. Some contain spaces.

I would like to search another array, called $event_name, for the usernames contained in $username_arr.

 

For example, "at 20.00, Steve Dobson went to the park".  If "Steve Dobson" in the array $username_arr, I want to know!!!

 

This is what I have got so far, although I have taken it out of the for loop as you can see.

if (preg_match('/^['.$username_arr[$i].']$/', $event_name[$j]))
{
// execute command
}

 

How should I go about doing this?

Link to comment
Share on other sites

There are a ton of things wrong w/ your regex but I'm not gonna get into that because you don't really need regex for this.

 

foreach ($event_name as $ev) {
  foreach ($username_arr as $u) {
    if ( stripos($ev, $u) !== false ) {
      // array of found users
      $found_users[] = $u;
    }
  }
}

 

Link to comment
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.