protected function getWordWrappedData($data, $prefix)
    {
        $lines = array();

        do {
            if (mb_strlen($data, '8bit') > 997) {
                $line = $prefix . ' ' . mb_strcut($data, 0, 996, 'utf-8') . "\\\n";
                $lines[] = $line;
                $lineLength = mb_strlen($line, '8bit') - 1;
                $dataLength = mb_substr($data, '8bit');
                $data = mb_substr(
                    $data,
                    $lineLength,
                    $dataLength - $lineLength,
                    '8bit'
                );
            } else {
                $lines[] = $prefix . ' ' . $data . "\n";
                $data = '';
            }
        } while ($data != '');

        return implode('', $lines);
    }
protected function getWordWrappedData($data, $prefix)
    {
        $lines = array();

        do {
            if (mb_strlen($data, '8bit') > 997) {
                $line = $prefix . ' ' . mb_strcut($data, 0, 996, 'utf-8') . "\\\n";
                $lines[] = $line;
                $lineLength = mb_strlen($line, '8bit') - 1;
                $dataLength = mb_substr($data, '8bit');
                $data = mb_substr(
                    $data,
                    $lineLength,
                    $dataLength - $lineLength,
                    '8bit'
                );
            } else {
                $lines[] = $prefix . ' ' . $data . "\n";
                $data = '';
            }
        } while ($data != '');

        return implode('', $lines);
    }
protected function getWordWrappedData ( $ data , $ prefix ) { $ lines = array ( ) ; do { if ( mb_strlen ( $ data , '8bit' ) > 997 ) { $ line = $ prefix . ' ' . mb_strcut ( $ data , 0 , 996 , 'utf-8' ) . "\\\n" ; $ lines [ ] = $ line ; $ lineLength = mb_strlen ( $ line , '8bit' ) - 1 ; $ dataLength = mb_substr ( $ data , '8bit' ) ; $ data = mb_substr ( $ data , $ lineLength , $ dataLength - $ lineLength , '8bit' ) ; } else { $ lines [ ] = $ prefix . ' ' . $ data . "\n" ; $ data = '' ; } } while ( $ data != '' ) ; return implode ( '' , $ lines ) ; }
Wraps strings at 1,000 bytes without splitting UTF-8 multibyte
characters

Each line is prepended with the specified line prefix. Wrapped lines
are automatically appended with \ characters.

Protocol strings are UTF-8 but maximum line length is 1,000 bytes.
<kbd>mb_strcut()</kbd> is used so we can limit line length by bytes
and not split characters across multiple lines.

@param string $data   the data to wrap.
@param string $prefix a single character to use as the line prefix. For
example, 'D' or '#'.

@return string the word-wrapped, prefixed string.

@see http://www.gnupg.org/documentation/manuals/assuan/Server-responses.html
Wraps strings at 1 000 bytes without splitting UTF - 8 multibyte characters