make use of str_starts_with / str_ends_with / str_contains

This commit is contained in:
Shish
2020-10-25 19:31:58 +00:00
parent c783ff0e8d
commit 19a6b39c70
21 changed files with 42 additions and 36 deletions

View File

@@ -345,15 +345,21 @@ function unparse_url($parsed_url)
if (!function_exists('str_starts_with')) {
function str_starts_with(string $haystack, string $needle): bool
{
$length = strlen($needle);
return (substr($haystack, 0, $length) === $needle);
return \strncmp($haystack, $needle, \strlen($needle)) === 0;
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle): bool
{
$length = strlen($needle);
$start = $length * -1; //negative
return (substr($haystack, $start) === $needle);
return $needle === '' || $needle === \substr($haystack, - \strlen($needle));
}
}
if (!function_exists('str_contains')) {
function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
}