@Immutable
    public static String addcslashes(Environment env, TraceInfo trace, String source, String characters) {
        boolean[] bitmap = parseCharsetBitmap(env, trace, characters);

        int length = source.length();
        StringBuilder sb = new StringBuilder(length * 5 / 4);

        for (int i = 0; i < length; i++) {
            char ch = source.charAt(i);

            if (ch >= 256 || !bitmap[ch]) {
                sb.append(ch);
                continue;
            }

            switch (ch) {
                case 0x07:
                    sb.append("\\a");
                    break;
                case '\b':
                    sb.append("\\b");
                    break;
                case '\t':
                    sb.append("\\t");
                    break;
                case '\n':
                    sb.append("\\n");
                    break;
                case 0xb:
                    sb.append("\\v");
                    break;
                case '\f':
                    sb.append("\\f");
                    break;
                case '\r':
                    sb.append("\\r");
                    break;
                default:
                    if (ch < 0x20 || ch >= 0x7f) {
                        // save as octal
                        sb.append("\\");
                        sb.append((char) ('0' + ((ch >> 6) & 7)));
                        sb.append((char) ('0' + ((ch >> 3) & 7)));
                        sb.append((char) ('0' + ((ch) & 7)));
                        break;
                    } else {
                        sb.append("\\");
                        sb.append(ch);
                        break;
                    }
            }
        }

        return sb.toString();
    }
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