Jump to content

Preg_Match()


Johnny2

Recommended Posts

I'm trying to use preg_match() properly to search a string for any of several words. Basically I'm testing if a string contains a naughty word.

 

This doesn't seem to work:

 

preg_match("/word1/word2/word3/",$string_to_examine);

 

What am I missing?

Link to comment
Share on other sites

I'm trying to use preg_match() properly to search a string for any of several words. Basically I'm testing if a string contains a naughty word.

 

This doesn't seem to work:

 

preg_match("/word1/word2/word3/",$string_to_examine);

 

What am I missing?

preg_match("/word/i", $string_to_examine); // The i allows for upper & lower case words.....

 

I personally do this : $user_edits = str_ireplace($patterns, $replacements, $text); //replace it

Link to comment
Share on other sites

preg_match("/word/i", $string_to_examine); // The i allows for upper & lower case words.....

 

I personally do this : $user_edits = str_ireplace($patterns, $replacements, $text); //replace it

 

 

Thanks for your reply Strider.

I am not looking to replace anything. I simply want to test if there is one (or more) swear-words in the string. I know how to use preg_match to test for a single swear-word. I just need to know how to write the command so that I can look for many swear words at the same time.

 

Do you know how to do this?

 

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...