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 do you use `stripos()` function in PHP, PHP 8, PHP 8.1, PHP 8.2, PHP 8.3 With Example. The `stripos()` function in PHP is used to find the position of the first occurrence of a substring in a string, regardless of case. This function is available in PHP 8.1 & 8.2 as well as in previous versions of PHP.
Here’s the syntax of the `stripos()` function:
stripos(string $haystack, string $needle, int $offset = 0): int|false
1. `$haystack`: The string to search within.
2. `$needle`: The substring to search for.
3. `$offset` (optional): The position in `$haystack` to start searching from. If specified, searching will start from this position.
It returns the position of the first occurrence of `$needle` within `$haystack`, or `false` if `$needle` is not found.
Here’s an example of how you can use `stripos()` in PHP 8.1 & 8.2:
<?php $haystack = "The quick brown fox jumps over the lazy dog"; $needle = "brown"; $position = stripos($haystack, $needle); if ($position !== false) { echo "The substring '$needle' was found at position: $position"; } else { echo "The substring '$needle' was not found in the string."; } ?>
In this example, `stripos()` is used to find the position of the substring `”brown”` in the string `$haystack`. Since the comparison is case-insensitive, it will find the position of both `”brown”` and `”Brown”`, if they exist in the string.