Example 1 — Check for a Word
Ask if one string contains another.
<?php
$text = "Learn PHP with CodeToFun";
if (str_contains($text, "PHP")) {
echo "Found PHP", PHP_EOL;
} else {
echo "No PHP", PHP_EOL;
} How It Works
- Pick a text. It has a few words.
- Call str_contains(). The haystack comes first.
- Get true.
PHPis inside the text. - Use it in if. No need for
!== false.

