public static Memory str_word_count(String string, int format, String additionalWordCharacters) {
        if (format < 0 || format > 2) {
            return Memory.NULL;
        }

        int strlen = string.length();
        boolean isAdditionalWordCharacters = false;

        if (additionalWordCharacters != null) {
            isAdditionalWordCharacters = additionalWordCharacters.length() > 0;
        }

        ArrayMemory resultArray = null;

        if (format > 0) {
            resultArray = new ArrayMemory();
        }

        boolean isBetweenWords = true;
        int wordCount = 0;
        int lastWordStart = 0;

        for (int i = 0; i <= strlen; i++) {
            boolean isWordCharacter;

            if (i < strlen) {
                int ch = string.charAt(i);

                isWordCharacter = Character.isLetter(ch)
                    || ch == '-'
                    || ch == '\''
                    || (isAdditionalWordCharacters
                    && additionalWordCharacters.indexOf(ch) > -1);
            } else {
                isWordCharacter = false;
            }

            if (isWordCharacter) {
                if (isBetweenWords) {
                    // starting a word
                    isBetweenWords = false;

                    lastWordStart = i;
                    wordCount++;
                }
            } else {
                if (!isBetweenWords) {
                    // finished a word
                    isBetweenWords = true;

                    if (format > 0) {
                        String word = string.substring(lastWordStart, i);

                        if (format == 1) {
                            resultArray.add(new StringMemory(word));
                        } else if (format == 2) {
                            resultArray.refOfIndex(lastWordStart).assign(word);
                        }
                    }
                }
            }
        }

        if (resultArray == null) {
            return LongMemory.valueOf(wordCount);
        } else {
            return resultArray.toConstant();
        }
    }
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