I have a string and need to check if any of the words in my list are in the string.
My list looks like this:
$keywords = array(
"l.*ion",
"test",
'one',
'two',
'three'
);
- If I have string
This is my lion
then I need to returntrue
.
- If I have string
This is my lotion
then I need to returntrue
.
- If I have string
This is my dandelion
then returnfalse
.
- If I have string
This is my location
then returntrue
.
- If I have string
This is my test
then returntrue
.
- If I have string
This is my testing
then returnfalse
.
This is my code:
$keywords = implode($keywords,"|");
$list= "/\b$keywords\b/i";
$my_string= "This is my testing";
preg_match($list, $my_string, $matches, PREG_OFFSET_CAPTURE);
echo $matches[0][1];
But when I do This is my testing
it returns a value.
What am I doing wrong?
I'm expecting a numerical value if its true and and error if its false.