Determine if a string starts with a particular sequence.

@param string $haystack
@param string $needle

@throws \InvalidArgumentException

@return bool
160032
public static function stringStartsWith($haystack, $needle)
    {
        if (!is_string($haystack) || !is_string($needle)) {
            throw new \InvalidArgumentException('Not a string');
        }

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

        return $fName($haystack, $needle) === 0;
    }
272412
public static function endsWith($haystack, $needle)
    {
        return $needle === '' or (($temp = mb_strlen($haystack) - mb_strlen($needle)) >= 0 and mb_strpos($haystack, $needle, $temp) !== false);
    }
324604
public static function contains($haystack, $needle, $ignoreCase = false)
    {
        if ($ignoreCase) {
            $needle = strtolower($needle);
            $haystack = strtolower($haystack);
        }
        $pos = strpos($haystack, $needle);

        return !($pos === false);
    }
927494
public static function contains(string $haystack, string $needle): bool
    {
        return mb_strpos($haystack, $needle, 0, 'UTF-8') !== false;
    }
1324042
protected function searchNamespace($needle, $haystack)
    {
        $needle = realpath($needle);
        $haystack = array_map('realpath', $haystack);

        $key = array_search($needle, $haystack);

        return is_string($key) ? trim($key, '\\') : null;
    }
1305625
public static function endsWith($haystack, $needle)
    {
        return $needle == substr($haystack, strlen($haystack) - strlen($needle));
    }
1191725
public static function within( $haystack, $needle, $offset = 0, $caseSensitive = false )
    {
        if ( false === $caseSensitive )
        {
            //	Case-insensitive
            return false !== stripos( $haystack, $needle, $offset );
        }

        //	Case-sensitive
        return false !== strpos( $haystack, $needle, $offset );
    }
1083698
public static function EndsWith($haystack, $needle)
    {
        $length = static::Length($needle);

        return $length === 0 || (substr($haystack, -$length) === $needle);
    }
1143622
public function starts_with( $haystack, $needle ) {
		if ( '' === $haystack || '' === $needle ) {
			return false;
		}
		if ( $haystack === $needle ) {
			return true;
		}

		return strncmp( $haystack, $needle, strlen( $needle ) ) === 0;
	}
229443
public static function StartsWith($haystack, $needle)
    {
        $length = static::Length($needle);

        return substr($haystack, 0, $length) === $needle;
    }
1077814
public static function hasEnding(string $needle, string $haystack): bool
    {
        return $needle === '' || substr($haystack, -strlen($needle)) === $needle;
    }
564123
public function strpos($haystack, $needle)
    {
        $hstck = '' . $haystack;
        $ndl = '' . $needle;
        if ($hstck === '' || $ndl === '') {
            return false;
        }
        if (static::$nativeSupport['mbstring']) {
            return mb_strpos($hstck, $ndl);
        }

        $pos = strpos($hstck, $ndl);
        if (!$pos) {
            return $pos;
        }
        return count(
            preg_split('//u', substr($hstck, 0, $pos), null, PREG_SPLIT_NO_EMPTY)
        );
    }
1003507
public static function contains(string $haystack, string $needle, int $offset = 0): bool
    {
        return self::strpos($haystack, $needle, $offset) !== false;
    }
658158
public function hasKey(string $needle, array $haystack) : bool
    {
        foreach ($haystack as $key => $value) {
            if ($key === $needle) {
                return true;
            }

            if (is_array($value)) {
                if ($x = $this->hasKey($needle, $value)) {
                    return $x;
                }
            }
        }

        return false;
    }
1190505
public function beginsWith(string $haystack, string $needle): bool
    {
        return (!empty($needle) && 0 === strpos($haystack, $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;
    }