I'll be using strpos to get the position and strtolower, so that the string isn't anymore case sensitive in my method
. So, here you go,
PHP Code:
<?php
function strstrbi($haystack, $needle, $before_needle=FALSE, $include_needle=TRUE, $case_sensitive=FALSE) {
//Find the position of $needle
if($case_sensitive) {
$pos=strpos($haystack,$needle);
} else {
$pos=strpos(strtolower($haystack),strtolower($needle));
}
//If $needle not found, abort
if($pos===FALSE) return FALSE;
//Adjust $pos to include/exclude the needle
if($before_needle==$include_needle) $pos+=strlen($needle);
//get everything from 0 to $pos?
if($before_needle) return substr($haystack,0,$pos);
//otherwise, go from $pos to end
return substr($haystack,$pos);
}
?>
Now, just call strstrbi with required number of arguments and you get the output string which is before the first occurence of delimeter.
Bookmarks