@Immutable
    public static String str_pad(String string, int length, String pad, int type) {
        int strLen = string.length();
        int padLen = length - strLen;

        if (padLen <= 0) {
            return string;
        }

        if (pad == null || pad.length() == 0) {
            pad = " ";
        }

        int leftPad = 0;
        int rightPad = 0;

        switch (type) {
            case 0:
                leftPad = padLen;
                break;
            case 1:
            default:
                rightPad = padLen;
                break;
            case 2:
                leftPad = padLen / 2;
                rightPad = padLen - leftPad;
                break;
        }

        int padStringLen = pad.length();

        StringBuilder sb = new StringBuilder(string.length() + padLen);

        for (int i = 0; i < leftPad; i++) {
            sb.append(pad.charAt(i % padStringLen));
        }
        sb = sb.append(string);
        for (int i = 0; i < rightPad; i++) {
            sb.append(pad.charAt(i % padStringLen));
        }

        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