Two bugs:
1) your linebreak is wrong
$linebreak = "\r\n";
2) continuation of lines with no whitespace is broken
/*
* the text after the whitespace will have to
* be read again ( + any additional characters
* that came into existence as a result of the
* encoding process after the whitespace)
*
* Also, do not start at 0, if there was *no*
* whitespace in the whole line
*/
if (($i + $addtl_chars) > $whitesp_diff) {
$output .= substr($cur_conv_line, 0,
(strlen($cur_conv_line) - $whitesp_diff)) .
$linebreak;
$i = $i - $whitesp_diff + $addtl_chars;
} else {
/* emit continuation --mirabilos */
$output .= $cur_conv_line .
'=' . $linebreak;
}