$position=stripos("Welcome to plus2et.com",'CO');
echo $position; // Output is 3

$int_position=stripos(Main_string, Search_string,[optional: offset =0 ]);
Main_string : The string inside of which the search_string will be searched. $position=stripos("Welcome to plus2et.com",'CO',4);
echo $position; // Output is 19, not 3
$position=stripos("Welcome to plus2et.com",'y');
if($position==false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
}
// Output is Not found
Using the same code we will search for sub-string W
$position=stripos("Welcome to plus2et.com",'W');
if($position==false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
}
// Output is Not found
The search string ( W ) is already present at position 0 . Above code need to change like this to get correct output.
$position=stripos("Welcome to plus2et.com",'w');
if($position===false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
} // Output is Found and position = 0
$position=stripos("Welcome to plus2et.com",'M');
if($position===false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
} // Output is Found and position = 5
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.