$position=strrpos("Welcome to plus2et.com",'m');
echo $position; // Optput is 21
$int_position=strrpos(Main_string, Search_string,[optional: offset =0 ]);
Main_string : The string inside of which the search_string will be searched. echo strrpos("Welcome to plus2et.com",'e'); // Output is 16
echo strrpos("Welcome to plus2et.com",'e', 3); // Output is 16
echo strrpos("Welcome to plus2et.com",'c',-1); // Output is 19
echo strrpos("Welcome to plus2et.com",'c',-4); // Output is 3
echo strrpos("Welcome to plus2et.com",'o',-1); // Output is 20
echo strrpos("Welcome to plus2et.com",'o',-4); // Output is 9
echo strrpos("Welcome to plus2et.com",'e',-4); // Output is 16
echo strrpos("Welcome to plus2et.com",'e',-7); // Output is 6
$position=strrpos("Welcome",'z');
if($position==false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
}
// Output is Not found
Using the same code we will search for string W
$position=strrpos("Welcome",'W');
if($position==false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
}
// Output is Not found
The search string is already present at position 0 . Above code need to change like this to get correct output.
$position=strrpos("Welcome",'W');
if($position===false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
} // Output is Found and position = 0
$position=strrpos("Welcome",'M');
if($position===false){
echo " Not found ";
}else{
echo " Found and position = ".$position;
} // Output is Not Found
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.