PHP Check if String Contains Word With Example

Hello Friends Today, through this tutorial, I will tell you How do you check if string contains word using PHP With Example? In PHP, you can check if a string contains a specific word or substring using the `strpos()` function or the `stripos()` function if you want to perform a case-insensitive search. Here’s how you can do it:

Using `strpos()`:

<?php
$string = "This is a sample string.";
$word = "sample";
if (strpos($string, $word) !== false) {
echo "The string contains the word '$word'.";
} else {
echo "The string does not contain the word '$word'.";
}
?>

Using `stripos()` for case-insensitive search:

<?php
$string = "This is a sample string.";
$word = "Sample";
if (stripos($string, $word) !== false) {
echo "The string contains the word '$word' (case-insensitive).";
} else {
echo "The string does not contain the word '$word' (case-insensitive).";
}
?>

In both cases, `strpos()` and `stripos()` return the position of the first occurrence of the substring in the string if found, and `false` otherwise. The `!== false` comparison ensures that you’re checking for a non-boolean false value, as `strpos()` and `stripos()` may return 0 if the substring is found at the beginning of the string, which would be considered falsy if you use a loose comparison (`!=`).

Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.