Using strrpos you can get the last occurrence. More on function.strrpos
For your purpose, you need to blow your string with $ and run the strrpos application for the first index in the parsed array.
Try the following:
$string="abc @def @xyz $ @def @xyz"; $strArr = explode('$', $string); $pos = strrpos($strArr[0], "@"); if ($pos === false) { // note: three equal signs echo 'Not Found!'; }else echo $pos; //Output 9 this case
source share