Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need it so that if I have a words like: "tire","hack","it," in an array it would find the words in this string: "re'tire'ment is pol'it'ly w'hack'y!"

I have this code which only works when the word is not part of another word but I was wondering if there was a way to find the word if it part of another word:
PHP
$bad = array("a","dog");

$string = $_POST['Username'];



                 if (0 < count(array_intersect(array_map('strtolower', explode(' ', $string)), $bad)))
        {
                 $errors[] = 'The user name must not contain any inapproprate language.';
        }
Posted
Updated 19-Dec-13 9:21am
v2

1 solution

You may use strpos function, see this Stack Overflow question: "How to check if a string contains specific words?"[^]
 
Share this answer
 
v2
Comments
SkyeEverest 19-Dec-13 15:43pm    
That would work bot I don't want to write out a new line for each word I am trying to find, cause that would take to long, and I want a simpler solution!
CPallini 19-Dec-13 15:50pm    
That's the basic solution. You have to modify it (e.g. using array and loops) in order to fit your needs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900