Jump to content

Recommended Posts

I'm a little stumped how to do this, so hopefully I'll find the right answer. I have two strings:

 

$customtitle and $censoredwords

 

Inside the $customtitle string is a user typed string consisting of words, letters, numbers, etc. Inside the $censoredwords are censored words or characters typed by the Administrator. Each word is seperated by a space, which is what is really confusing me.

 

My question to you is how can I compare the two strings and see if $customtitle contains any words from $censoredwords and if so kickback a TRUE or numerical value of 1 and if not kick back a FALSE or a numerical value of 0.

Link to comment
https://forums.phpfreaks.com/topic/201956-comparing-two-strings/
Share on other sites

I would create $censoredwords to an array of strings. Then use a for loop or maybe a foreach loop to compare the strings.

 

Here is some code on the spot:

$title = "mean";
$censored = array("stupid", "mean", "gay");
for($i=0; $i<count($censored); $i++){
  if($censored[$i] == $title){
      echo "naughty word";
      break;
  }
}

 

Not sure if that code is all correct, I kinda did it real quick.

Not sure if this would work or not.. I just wrote this until someone can help me with my problem :)

 

        <?php
        
        $customtitle = "This is my custom title poop";
        $customtitle = explode(" ", $customtitle);
        
        $censoredwords = "poop dang";
        $censoredwords = explode(" ", $censoredwords);
        
        foreach($customtitle as $word)
        {
            
            if(in_array($word, $censoredwords))
            {
                // do whatever here.. like flag the title as bad or whatever
                echo "Shame on you! " . $word . " is a bad word!";
                
            }
            
        }
        
        ?>

 

Obviously there's better ways to write this, but you get the idea.. oh and this is untested, but it should work.

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.