replaces all occurrences of needle in haystack with newNeedle
the input itself is not modified

@param haystack  input string
@param needle	string to replace
@param newNeedle replacement
420300
public static void replaceAll(StringBuffer haystack, String needle, String newNeedle) {
/*		if(needle == null || "".equals(needle))
		{
			throw new IllegalArgumentException("string to replace may not be empty");
		}
		int idx = haystack.indexOf(needle);
		int needleLength = needle.length();
		int newNeedleLength = newNeedle.length();
		while (idx != -1)
		{
			haystack.replace(idx, idx + needleLength, newNeedle);
			idx = haystack.indexOf(needle, idx + newNeedleLength);
		}*/
		replaceAll(haystack, needle, newNeedle, 0);
	}
417654
public static function stringEndsWith($haystack, $needle)
    {
        if (substr($haystack, - strlen($needle)) === $needle) {
            return true;
        }

        return false;
    }
1146110
public function arrayKeyExistsRecursiveExtended(string $needle, array $haystack): bool
    {
        $result = false;
        foreach ($haystack as $value) {
            if (true === is_array($value)) {
                $result = $this->arrayKeyExistsRecursive($needle, $value);
            }
            if (true === $result) {
                return $result;
            }
        }

        return $result;
    }
31724
public static function hasBeginning(string $needle, string $haystack): bool
    {
        return $needle === '' || strpos($haystack, $needle) === 0;
    }
14261
private function _inArray($needle, $haystack) {
		foreach ($haystack as $strand) {
			if (fnmatch($strand, $needle)) {
				return true;
			}
		}
		return false;
	}
1310778
public static function in($needle, ?array $haystack = null, bool $strict = true): bool
    {
        // prevent errors
        if (!Any::isArray($haystack) || $needle === null) {
            return false;
        }

        return in_array($needle, $haystack, $strict);
    }
898160
function(needle, haystack) {
		var m = false;

		for (var i in haystack) {
			if (i === '*') m = '*';
			else if (urlglob(i, needle)) return i;
		}

		return m;
	}
5987
public static function in_array_all($needles, $haystack)
    {
        foreach ($needles as $n) {
            if (!in_array($n, $haystack)) {
                return false;
            }
        }

        return true;
    }
1051470
public static function indexOf(string $haystack, string $needle, int $nth = 1): ?int
    {
        $pos = static::pos($haystack, $needle, $nth);

        return $pos === null
            ? null
            : \mb_strlen(\substr($haystack, 0, $pos));
    }
1325767
public function ends_with( $haystack, $needle ) {
		if ( '' === $haystack || '' === $needle ) {
			return false;
		}
		if ( $haystack === $needle ) {
			return true;
		}

		return substr_compare( $haystack, $needle, - strlen( $needle ) ) === 0;
	}
690571
public static function inString($needle, $haystack, $insensitive = false)
    {
        if ($insensitive) {
            return false !== stristr($haystack, $needle);
        }

        return false !== strpos($haystack, $needle);
    }
775758
public static String replaceAll(String haystack, String[] needle, String newNeedle[]) {
		if (needle.length != newNeedle.length) {
			throw new IllegalArgumentException("length of original and replace values do not match (" + needle.length + " != " + newNeedle.length + " )");
		}
		StringBuffer buf = new StringBuffer(haystack);
		for (int i = 0; i < needle.length; i++) {
			//TODO not very elegant

			replaceAll(buf, needle[i], newNeedle[i]);
		}
		return buf.toString();
	}
133302
public static function after(
        string $haystack,
        string $needle,
        bool $useLastNeedle = false
    ): string
    {
        $pos = static::getNeedlePosition($haystack, $needle, $useLastNeedle);
        if ($pos === false) {
            return $haystack;
        }
        return substr($haystack, $pos + strlen($needle));
    }
1013213
protected function stringHasStatement( $haystack, $needle ) {
		$pattern = '~^\s*(' . preg_quote( $needle, '~' ) . ')\s*$~m';
		return (bool) preg_match( $pattern, $haystack );
	}
1360988
public static function unsetInArrayByValue($needle, array $haystack, $reIndex = true)
    {
        $doReindex = false;

        foreach($haystack as $key => $value) {
            if (is_array($value)) {
                $haystack[$key] = static::unsetInArrayByValue($needle, $value);
            } else if ($needle === $value) {

                unset($haystack[$key]);

                if ($reIndex) {
                    $doReindex = true;
                }
            }
        }

        if ($doReindex) {
            $haystack = array_values($haystack);
        }

        return $haystack;
    }
111756
public static function startsWith($haystack, $needle)
    {
        return $needle === '' or mb_strrpos($haystack, $needle, -mb_strlen($haystack)) !== 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;
    }