Hello,

I only saw you mention strpos, preg_match and substr as (slower) alternatives. However, there's already a function called substr_compare which is meant for just this kind of comparisons but which is more general than your RFC.

function str_begins($a, $b) {
  return substr_compare($a, $b, 0, strlen($b)) === 0;
}
function str_ends($a, $b) {
  return substr_compare($a, $b, -strlen($b)) === 0;
}

--
Lauri Kenttä

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to