0

I have list of words that needs to check is exact available or in string. Also words may be case sensitive.

For e.g. 1

Hello world how are

I tried,

preg_match()

$url      = "Hello world how are you ?";
$haystack = "Hello|world|how|are";
$check    = (preg_match("({$haystack})", $url) === 1);
var_dump($check);

Output

true

Try it online!

This example checks like or operator.

For e.g. 2

strpos().

$url      = "Hello world how are you ?";
$check    = (strpos($url, "Hello") >= 0 && strpos($url, "world") && strpos($url, "how") && strpos($url, "are"));
var_dump($check);

Output

true

Try it online!

This example working but not check exact match try to change first Hello word to hellosssss it shows always true.

So, any preferable way to check all words exactly and also with case sensitive.

Note : This example shows only few words but I have many words.

Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39

0 Answers0