/**
* @param string $haystack
* @param string $needle
* @return boolean whether $haystack starts with substring $needle
*/
function starts_with($haystack, $needle) {
return (strpos($haystack, $needle) === 0);
}
/**
* @param string $haystack
* @param string $needle
* @return boolean whether $haystack ends with substring $needle
*/
function ends_with($haystack, $needle) {
return (strrevpos($haystack, $needle) === (strlen($haystack) - strlen($needle)));
}
Comments
Comment #1
crystaldawn commentedWhat do you think would be the difference between these to functions and the before/after functions? Would they be faster than before/after? I think the only advantage would be memory consumption. One could return a 50K block while the bools only return a single number. I dont know what I'd ever use it for since the only time I ever use before/after as a bool check is when the line is really small anyways but I can see that it might possibly be needed if your return value was really big if you tried to use before/after. I'll put these in they seem like a good addition for completeness.
Comment #2
crystaldawn commentedI've added these and added a new release 5--1-8 and 6--1-8.
Comment #3
arhak commentedcoming from Java programming, those are part of the String class, that's why those seems so natural for me