mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add case insensitive string helper functions.
This commit is contained in:
@ -1389,6 +1389,24 @@ function str_contains($haystack, $needles)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a given string contains a given substring.
|
||||||
|
* Case Insensitive.
|
||||||
|
*
|
||||||
|
* @param string $haystack
|
||||||
|
* @param string|array $needles
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function str_icontains($haystack, $needles)
|
||||||
|
{
|
||||||
|
foreach ((array) $needles as $needle) {
|
||||||
|
if ($needle != '' && stripos($haystack, $needle) !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a given string ends with a given substring.
|
* Determine if a given string ends with a given substring.
|
||||||
*
|
*
|
||||||
@ -1406,6 +1424,24 @@ function ends_with($haystack, $needles)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a given string ends with a given substring.
|
||||||
|
* Case insensitive.
|
||||||
|
*
|
||||||
|
* @param string $haystack
|
||||||
|
* @param string|array $needles
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function iends_with($haystack, $needles)
|
||||||
|
{
|
||||||
|
$lower_haystack = strtolower($haystack);
|
||||||
|
foreach ((array)$needles as $needle) {
|
||||||
|
if (strtolower($needle) === substr($lower_haystack, -strlen($needle))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a given string starts with a given substring.
|
* Determine if a given string starts with a given substring.
|
||||||
@ -1423,3 +1459,21 @@ function starts_with($haystack, $needles)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a given string starts with a given substring.
|
||||||
|
* Case insensitive.
|
||||||
|
*
|
||||||
|
* @param string $haystack
|
||||||
|
* @param string|array $needles
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function istarts_with($haystack, $needles)
|
||||||
|
{
|
||||||
|
foreach ((array)$needles as $needle) {
|
||||||
|
if ($needle != '' && stripos($haystack, $needle) === 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user