@Immutable
    public static Memory substr_count(Environment env, TraceInfo trace,
                                      String haystack, String needle, int offset, Memory _length) {
        if (needle.isEmpty()) {
            env.warning(trace, "Empty substring");
            return Memory.FALSE;
        }

        int haystackLength = haystack.length();

        if (offset < 0) {
            env.warning(trace, "Offset should be greater than or equal to 0");
            return Memory.FALSE;
        }

        if (offset > haystackLength) {
            env.warning(trace, "Offset value %s exceeds string length", offset);
            return Memory.FALSE;
        }

        int length;
        int end;
        int needleLength = needle.length();

        if (_length != null) {
            length = _length.toInteger();
            end = offset + length - 1;

            if (length <= 0) {
                env.warning(trace, "Length should be greater than 0");
                return Memory.FALSE;
            }

            if (length > (haystackLength - offset)) {
                env.warning(trace, "Length value %s exceeds string length", length);
                return Memory.FALSE;
            }
        } else {
            end = haystackLength - needleLength + 1;
        }

        int count = 0;

        if (needleLength == 1) {
            char ch = needle.charAt(0);
            for (int i = offset; i < end; i++) {
                if (ch == haystack.charAt(i))
                    count++;
            }
        } else {
            for (int i = offset; i < end; i++) {
                if (haystack.startsWith(needle, i)) {
                    count++;
                    i += needleLength;
                }
            }
        }

        return LongMemory.valueOf(count);
    }
Parses the cslashes bitmap returning an actual bitmap.

@param charset the bitmap string

@return the actual bitmap
exts/jphp-zend-ext/src/main/java/org/develnext/jphp/zend/ext/standard/StringFunctions.java