Returns position of $nth occurence of $needle in $haystack.

@param string $haystack
@param string $needle
@param int    $nth

@return int|null  offset in bytes or FALSE if the needle was not found
196962
private static function pos(string $haystack, string $needle, $nth = 1): ?int
    {
        if (!$nth) {
            return null;
        }

        if ($nth > 0) {
            if ($needle === '') {
                return 0;
            }
            $pos = 0;
            while (false !== ($pos = \strpos($haystack, $needle, $pos)) && --$nth) {
                $pos++;
            }
        } else {
            $len = \strlen($haystack);
            if ($needle === '') {
                return $len;
            }
            $pos = $len - 1;
            while (false !== ($pos = \strrpos($haystack, $needle, $pos - $len)) && ++$nth) {
                $pos--;
            }
        }

        return $pos;
    }
10014
public static function indexOf(string $haystack, string $needle, int $offset = 0): int
    {
        $pos = self::strpos($haystack, $needle, $offset);
        return is_int($pos) ? $pos : -1;
    }
1013213
protected function stringHasStatement( $haystack, $needle ) {
		$pattern = '~^\s*(' . preg_quote( $needle, '~' ) . ')\s*$~m';
		return (bool) preg_match( $pattern, $haystack );
	}
242331
public static function endswith($haystack, $needle) {
    $haylen  = strlen($haystack);
    $needlelen = strlen($needle);
    if ($needlelen > $haylen)
      return false;

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

        return substr($haystack, 0, $length) === $needle;
    }
1112711
public function arrayMultiSearch($needle, $haystack) {
        foreach ($haystack as $key => $data) {
            if (in_array($needle, $data)) {
                return $key;
            }
        }
        return false;
    }
981782
public static function getNeedlePositions($haystack, $needle)
    {
        $start = 0;
        $result = array();
        $needleLength = strlen($needle);

        while (($pos = strpos($haystack, $needle, $start)) !== false) {
            $start = $pos + 1;

            // Calculate starting and ending positions
            $startPos = $pos;
            $endPos = $pos + $needleLength;

            // Save them
            $result[$startPos] = $endPos;
        }

        return $result;
    }
394347
public static function subCount($haystack, $needle)
    {
        if (self::isMBString()) {
            return mb_substr_count($haystack, $needle, self::$encoding);
        }

        return substr_count($haystack, $needle); // @codeCoverageIgnore
    }
521361
private static int count(final String needle, final String haystack) {
        int count = 0;
        int pos = -1;
        while ((pos = haystack.indexOf(needle, pos + 1)) >= 0) {
            count++;
        }
        return count;
    }
583910
public static function pos($haystack, $needle, $offset = 0)
    {
        if (self::isMBString()) {
            return mb_strpos($haystack, $needle, $offset, self::$encoding);
        }

        return strpos($haystack, $needle, $offset); // @codeCoverageIgnore
    }
1083698
public static function EndsWith($haystack, $needle)
    {
        $length = static::Length($needle);

        return $length === 0 || (substr($haystack, -$length) === $needle);
    }
649501
public static function startsWith($haystack, $needle)
    {
        if (strlen($haystack) < strlen($needle)) {
            return false;
        }
        $start = substr($haystack, 0, strlen($needle));

        return $needle === "" || $needle === $start;
    }
441400
public static function startsWith($haystack, $needle)
    {
        $length = strlen($needle);

        return substr($haystack, 0, $length) === $needle;
    }
138235
public static function contains($haystack, $needle)
    {
        foreach ((array)$needle as $n) {
            if (strpos($haystack, $n) !== false) {
                return true;
            }
        }

        return false;
    }
310917
public static function substrInArray($needle, array $haystack)
    {
        $filtered = array_filter(
            $haystack,
            function($item) use ($needle) {
                return false !== strpos($item, $needle);
            }
        );

        /** @noinspection IsEmptyFunctionUsageInspection */
        return !empty($filtered);
    }
263334
public static function Position ($haystack, $needle, $offset = 0, $encoding = Encoding::DEFAULT_ENCODING) {
		return mb_strpos($haystack, $needle, $offset, $encoding);
	}
811711
protected function tagSearch($needle, array $haystack)
    {
        foreach ($haystack as $actual) {
            if (0 === strcasecmp($needle, $actual)) {
                return $actual;
            }
        }

        return null;
    }