Add startsWith to core

This commit is contained in:
Starbeamrainbowlabs 2017-04-17 13:00:40 +01:00
parent 725a472880
commit 477e065375
1 changed files with 9 additions and 0 deletions

View File

@ -363,6 +363,15 @@ function mb_stripos_all($haystack, $needle) {
return false;
}
/**
* Tests whether a string starts with a specified substring.
* @param string $haystack The string to check against.
* @param string $needle The substring to look for.
* @return bool Whether the string starts with the specified substring.
*/
function startsWith($haystack, $needle) {
return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
}
/**
* Tests whether a string ends with a given substring.
* @param string $whole The string to test against.