In Java, we can use indexOf
and lastIndexOf
. Since those functions don\'t exist in PHP, what would be the PHP equivalent of this Java code?
<
In php:
stripos() function is used to find the position of the first occurrence of a case-insensitive substring in a string.
strripos() function is used to find the position of the last occurrence of a case-insensitive substring in a string.
Sample code:
$string = 'This is a string';
$substring ='i';
$firstIndex = stripos($string, $substring);
$lastIndex = strripos($string, $substring);
echo 'Fist index = ' . $firstIndex . ' ' . 'Last index = '. $lastIndex;
Output: Fist index = 2 Last index = 13