stristr() Function in PHP With Example

Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.

Hello Friends Today, through this tutorial, I will tell you How to Use `stristr()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, the `stristr()` function is used to perform a case-insensitive search for a substring within another string. This function returns the part of the haystack (the string being searched) from the first occurrence of needle (the substring being searched for) to the end of the haystack, or FALSE if needle is not found.

Here’s the syntax for the `stristr()` function:

<?php
stristr(string $haystack, string $needle, bool $before_needle = false): string|false
?>

Parameters:
1. `$haystack`: The string to search in.
2. `$needle`: The substring to search for.
3. `$before_needle` (optional): If set to TRUE, `stristr()` returns the part of the haystack before the first occurrence of the needle. Default is FALSE.

Example:

<?php
$haystack = "Hello, world! This is a test string.";
$needle = "world";
// Case-insensitive search for "world" in $haystack
$result = stristr($haystack, $needle);
if ($result !== false) {
echo "Found: $result"; // Output: Found: world! This is a test string.
} else {
echo "Not found.";
}
?>

In this example, `stristr()` searches for the substring “world” in the haystack string. Since the search is case-insensitive, it finds “world” within the haystack, and the part of the haystack starting from “world” to the end is returned.

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.