mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
String helper functions
Bring some sanity to the madness
This commit is contained in:
@@ -1336,3 +1336,54 @@ function ResolveGlues($tables,$target,$x=0,$hist=array(),$last=array()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string contains a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function str_contains($haystack, $needles)
|
||||
{
|
||||
foreach ((array) $needles as $needle) {
|
||||
if ($needle != '' && strpos($haystack, $needle) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given string ends with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function ends_with($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ((string)$needle === substr($haystack, -strlen($needle))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a given string starts with a given substring.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string|array $needles
|
||||
* @return bool
|
||||
*/
|
||||
function starts_with($haystack, $needles)
|
||||
{
|
||||
foreach ((array)$needles as $needle) {
|
||||
if ($needle != '' && strpos($haystack, $needle) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user