Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:35:28+00:00 2026-06-02T07:35:28+00:00

I have an app that I’m developing, in it users can choose a name

  • 0

I have an app that I’m developing, in it users can choose a name for themselves. I need to be able to filter out “bad” names, so I do this for now:

$error_count=0;

$bad_names="badname1badname2";

preg_match_all("/\b".$user_name."\b/i",$global['bad_names'],
  $matches,PREG_OFFSET_CAPTURE);

if(count($matches[0])>0)
{
  $error_count++;
}

This would tell me if the user’s name was inside the bad names list, however, it doesn’t tell me if the bad name itself is in the user’s name. They could combine a bad word with something else and I wouldn’t detect it.

What kind of regex (if I even use regex) would I use for this? I need to be able to take any bad name (preferably in an array like $bad_names), and search through the user’s name to see whether that word is within their name. I’m not great with regex, and the only way I can think of is to put it all through a loop which seems highly inefficient. Anyone have a better idea? I guess I need to figure out how to search through a string with an array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:35:29+00:00Added an answer on June 2, 2026 at 7:35 am
    $badnames = array('name1', 'name2');
    
    // you need to quote the names so they can be inserted into the
    // regular expression safely
    $badnames_quoted = array();
    foreach ($badnames as $name) {
        $badnames_quoted[] = preg_quote($name, '/');
    }
    
    // now construct a RE that will match any bad name
    $badnames_re = '/\b('.implode('|', $badnames_quoted).')\b/Siu';
    
    // no need to gather all matches, or even to see what matched
    $hasbadname = preg_match($badnames_re, $thestring);
    if ($hasbadname) {
        // bad name found
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have an app that finds your GPS location successfully, but I need to be
I have an app that I've collected crash reports for that I can't reproduce.
I have an app that will display Lotto Max numbers, I need to make
I have an app that I want to be able to build two different
I have an app that currently shows a message box when the users saves
I have an app that runs on the iPhone and iPod Touch, it can
I have an app that I've been working on, but now I need to
i have an app that will be shipped by different providers. So i need
I have an app that uses Apples reachability code. When I tab out of
Have an app that can use tts to read text messages. It can also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.