If you want to use the $before_needle parameter that's only in PHP 5.3.0, I found a way to use it in lower versions.
The code is a bit hefty, but it works. It also has added $include_needle and $case_sensitive.
<?php
function strstrbi($haystack,$needle,$before_needle,
$include_needle,$case_sensitive)
{
$strstr = ($case_sensitive) ? 'strstr' : 'stristr';
if($before_needle!=true && $before_needle!=false && isset($before_needle)){
die('PHP: Error in function '.chr(39).'$strstrbi'. chr(39).' : parameter '. chr(39).'$before_needle'.chr(39).' is not a supplied as a boolean.');
} if($include_needle!=true && $include_needle!=false && isset($include_needle)){
die('PHP: Error in function '.chr(39).'$strstrbi'. chr(39).' : parameter '. chr(39).'$include_needle'.chr(39). ' is not a supplied as a boolean.');
} if($case_sensitive!=true && $case_sensitive!=false && isset($case_sensitive)){
die('PHP: Error in function '.chr(39).'$strstrbi' .chr(39).' : parameter '. chr(39).'$case_sensitive'.chr(39).' is not a supplied as a boolean.');
} if(!isset($before_needle)){
$before_needle=false;
}
if(!isset($include_needle)){
$include_needle=true;
}
if(!isset($case_sensitive)){
$case_sensitive=false;
}
switch($before_needle){
case true:
switch($include_needle){
case true:
$temp=strrev($haystack);
$ret=strrev(substr($strstr($temp,$needle),0));
break;
case false:
$temp=strrev($haystack);
$ret=strrev(substr($strstr($temp,$needle),1));
break;
}
break;
case false:
switch($include_needle){
case true:
$ret=$strstr($haystack,$needle);
break;
case false:
$ret=substr($strstr($haystack,$needle),1);
break;
}
break;
}
if(!empty($ret)){
return $ret;
}else{
return false;
}
}
$email = 'user@example.com';
$domain = strstrbi($email, '@', false, false, false);
echo $domain; $user = strstrbi($email, '@', true, false, false);
echo $user; ?>