/**
 * @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

crystaldawn’s picture

Status: Needs review » Patch (to be ported)

What 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.

crystaldawn’s picture

Status: Patch (to be ported) » Fixed

I've added these and added a new release 5--1-8 and 6--1-8.

arhak’s picture

coming from Java programming, those are part of the String class, that's why those seems so natural for me

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.