mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 22:38:42 +00:00
allowing arrays and string
This commit is contained in:
parent
d0222c7709
commit
8c79ec1a86
|
|
@ -42,65 +42,105 @@ class StringUtils
|
||||||
/**
|
/**
|
||||||
* String ends with?
|
* String ends with?
|
||||||
*
|
*
|
||||||
* @param string $haystack Haystack
|
* @param string $haystack Haystack
|
||||||
* @param string $needle Needle
|
* @param string|array $needles Needles
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn
|
* @author Dennis Eichhorn
|
||||||
*/
|
*/
|
||||||
public static function endsWith(string $haystack, string $needle) : bool
|
public static function endsWith(string $haystack, $needles) : bool
|
||||||
{
|
{
|
||||||
return $needle === '' || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
|
if (is_string($needles)) {
|
||||||
|
self::endsWith($haystack, [$needles]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($needles as $needle) {
|
||||||
|
if ($needle === '' || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String starts with?
|
* String starts with?
|
||||||
*
|
*
|
||||||
* @param string $haystack Haystack
|
* @param string $haystack Haystack
|
||||||
* @param string $needle Needle
|
* @param string|array $needles Needles
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn
|
* @author Dennis Eichhorn
|
||||||
*/
|
*/
|
||||||
public static function startsWith(string $haystack, string $needle) : bool
|
public static function startsWith(string $haystack, $needles) : bool
|
||||||
{
|
{
|
||||||
return $needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false;
|
if (is_string($needles)) {
|
||||||
|
self::startsWith($haystack, [$needles]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($needles as $needle) {
|
||||||
|
if ($needle === '' || strrpos($haystack, $needle, -strlen($haystack)) !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String starts with?
|
* String starts with?
|
||||||
*
|
*
|
||||||
* @param string $haystack Haystack
|
* @param string $haystack Haystack
|
||||||
* @param string $needle Needle
|
* @param string|array $needles Needles
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn
|
* @author Dennis Eichhorn
|
||||||
*/
|
*/
|
||||||
public static function mb_startsWith(string $haystack, string $needle) : bool
|
public static function mb_startsWith(string $haystack, $needles) : bool
|
||||||
{
|
{
|
||||||
return $needle === '' || mb_strrpos($haystack, $needle, -mb_strlen($haystack)) !== false;
|
if (is_string($needles)) {
|
||||||
|
self::mb_startsWith($haystack, [$needles]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($needles as $needle) {
|
||||||
|
if ($needle === '' || mb_strrpos($haystack, $needle, -mb_strlen($haystack)) !== false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String ends with?
|
* String ends with?
|
||||||
*
|
*
|
||||||
* @param string $haystack Haystack
|
* @param string $haystack Haystack
|
||||||
* @param string $needle Needle
|
* @param string|array $needles Needles
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn
|
* @author Dennis Eichhorn
|
||||||
*/
|
*/
|
||||||
public static function mb_endsWith(string $haystack, string $needle) : bool
|
public static function mb_endsWith(string $haystack, $needles) : bool
|
||||||
{
|
{
|
||||||
return $needle === '' || (($temp = mb_strlen($haystack) - mb_strlen($needle)) >= 0 && mb_strpos($haystack, $needle, $temp) !== false);
|
if (is_string($needles)) {
|
||||||
|
self::mb_endsWith($haystack, [$needles]);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($needles as $needle) {
|
||||||
|
if ($needle === '' || (($temp = mb_strlen($haystack) - mb_strlen($needle)) >= 0 && mb_strpos($haystack, $needle, $temp) !== false)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user