String helper functions

Bring some sanity to the madness
This commit is contained in:
Tony Murray
2016-08-19 14:57:08 -05:00
parent c3d2dca6a3
commit fd34c24f5c

View File

@@ -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;
}