In Addition to david lionhead's function:
<?php
function quoted_printable_encode($txt) {
/* Make sure there are no %20 or similar */
$txt = rawurldecode($txt);
$tmp="";
$line="";
for ($i=0;$i<strlen($txt);$i++) {
if (($txt[$i]>='a' && $txt[$i]<='z') || ($txt[$i]>='A' && $txt[$i]<='Z') || ($txt[$i]>='0' && $txt[$i]<='9')) {
$line.=$txt[$i];
if (strlen($line)>=75) {
$tmp.="$line=\n";
$line="";
}
}
else {
/* Important to differentiate this case from the above */
if (strlen($line)>=72) {
$tmp.="$line=\n";
$line="";
}
$line.="=".sprintf("%02X",ord($txt[$i]));
}
}
$tmp.="$line\n";
return $tmp;
}
?>