// ==== I don't guarantee this is faster than the PHP 6 before needle, ====
// ==== but it works for PHP below 6 atleast. ====
// ==== IT ALSO HAS INCLUDE NEEDLE BOOLEAN.. ====
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.');
} // END BOOLEAN CHECK '$before_needle'
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.');
} // END BOOLEAN CHECK '$include_needle'
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.');
} // END BOOLEAN CHECK '$case_sensitive'
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;
// END case true : $include_needle
case false:
$temp=strrev($haystack);
$ret=strrev(substr($strstr($temp,$needle),1));
break;
// END case false : $include_needle
}
break;
// END case true : $before_needle
case false:
switch($include_needle){
case true:
$ret=$strstr($haystack,$needle);
break;
// END case true: $include_needle
case false:
$ret=substr($strstr($haystack,$needle),1);
break;
// END case false: $include_needle
}
break;
// END case false : $before_needle
}
if(!empty($ret)){
return $ret;
}else{
return false;
}
}
// === END FUNCTION 'strstrbi'
// Example
$email = 'user@example.com';
$domain = strstrbi($email, '@', false, false, false);
echo $domain; // prints example.com
$user = strstrbi($email, '@', true, false, false);
echo $user; // prints user
?>