Check if string ends with another string

@param string $needle String to look for
@param string $haystack String to check
@param bool $caseSensitive Case sensitive check

@return bool
168266
public static function endsWith($needle, $haystack, $caseSensitive = true)
    {
        list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);

        return (self::substring($haystack, -(self::length($needle))) === $needle);
    }
742125
public static function stringBeginsWith($haystack, $needle)
    {
        if (!empty($needle) && strncmp($haystack, $needle, strlen($needle)) === 0) {
            return true;
        }

        return false;
    }
1043630
public static function containsCaseless($haystack, $needles)
    {
        foreach ((array) $needles as $needle) {
            $needle = preg_quote($needle);
            if ($needle != '' && preg_match("/$needle/iu", $haystack)) {
                return true;
            }
        }

        return false;
    }
828865
public function containsFilter($haystack, $needle)
    {
        if (empty($needle)) {
            return $haystack;
        }

        return (strpos($haystack, (string) $needle) !== false);
    }
1058277
public static function startsWith(
        string $haystack,
        string $needle,
        $caseSensitive = true
    ) : bool {
        $fName = $caseSensitive ? 'strpos' : 'stripos';

        return $fName($haystack, $needle) === 0;
    }
284571
public static function array_isearch($needle, array $haystack, bool $strict=true) {
		if (! \count($haystack)) {
			return false;
		}

		// Lowercase for comparison.
		ref\mb::strtolower($needle, true);
		ref\mb::strtolower($haystack, true);

		// phpcs:disable
		return array_search($needle, $haystack, $strict);
		// phpcs:enable
	}
1083698
public static function EndsWith($haystack, $needle)
    {
        $length = static::Length($needle);

        return $length === 0 || (substr($haystack, -$length) === $needle);
    }
947384
public static function contains($haystack, $needle, $caseSensitive = true)
    {
        return ($caseSensitive ? strpos($haystack, $needle) : stripos($haystack, $needle)) !== false;
    }
717873
public static function end_with($string, $needle, $case_sensitive = true)
    {
        if(!is_string($string))
        {
            $string = (string)$string;
        }
        
        if(!is_string($needle))
        {
            $needle = (string)$needle;
        }
        
        if($case_sensitive)
        {
            return strrpos($string, $needle) === strlen($string) - strlen($needle);
        }
        else
        {
            return strripos($string, $needle) === strlen($string) - strlen($needle);
        }
    }
905528
public static function ends($haystack, $needle, $caseSensitive = false): bool
    {
        if ($caseSensitive === true) {
            return $needle === '' || mb_substr($haystack, -mb_strlen($needle)) === $needle;
        }
        $haystack = mb_strtolower($haystack);
        $needle = mb_strtolower($needle);

        return $needle === '' || mb_substr($haystack, -mb_strlen($needle)) === $needle;
    }
1340777
public static function contains( $haystack, $needles )
    {
        foreach ( ( array ) $needles as $needle )
        {
            if ( '' !== $needle && FALSE !== strpos( $haystack, $needle ) )
            {
                return TRUE;
            }
        }

        return FALSE;
    }
697528
public static function startsWith($haystack, $needle, $case_sensitive = true)
    {
        $status = false;

        $compare_func = $case_sensitive ? 'mb_strpos' : 'mb_stripos';

        foreach ((array)$needle as $each_needle) {
            $status = $each_needle === '' || $compare_func($haystack, $each_needle) === 0;
            if ($status) {
                break;
            }
        }

        return $status;
    }
374853
public static function checkIfContainsAnyOf($haystack, $needles) {
		foreach ($needles as $needle) {
			if (self::checkIfContains($haystack, $needle)) return true;
		}
		return false;
	}
1059153
public static function contains(string $haystack, string $needle, bool $caseSensitive = true)
    {
        if ($caseSensitive) {
            return $needle === '' || strpos($haystack, $needle) !== false;
        }

        return $needle === '' || stripos($haystack, $needle) !== false;
    }
1055804
public function endsWith($needle, $caseSensitive = null)
    {
        if ('' === $needle) {
            return true;
        }
        if (null === $caseSensitive) {
            $caseSensitive = false;
        }

        $end = mb_substr($this->string(), -mb_strlen($needle));

        if ($caseSensitive) {
            return $end === $needle;
        }

        return mb_strtolower($end) === mb_strtolower($needle);
    }
160644
private function endsWith($haystack, $needle)
    {
        $length = strlen($needle);
        if ($length === 0) {
            return true;
        }

        return substr($haystack, -$length) === $needle;
    }
253440
public static function beginsWith(
        string $haystack,
        string $needle,
        bool $caseSensitive = false
    ): bool
    {
        $length = strlen($needle);
        return ($caseSensitive === false)
            ? strncasecmp($haystack, $needle, $length) === 0
            : strncmp($haystack, $needle, $length) === 0;
    }