Version: 0.1
Type: Function
Category: Algorithms
License: GNU General Public License
Description: This function converts a string to a quoted printable string. It uses PERL regular expression to do it.
<? function QuotedPrintableEncode($sString) { /* strip CR */ $sString = preg_replace("~[r]*~", "", $sString); /* encode characters */ $sString = preg_replace("~([x01-x08x10-x1Fx3Dx7F-xFF])~e", "sprintf('=%02X', ord('1'))", $sString); /* encode blanks and tabs */ $sString = preg_replace("~([x09x20])n~e", "sprintf('=%02Xn', ord('1'))", $sString); /* split string */ $aStrParts = explode("n", $sString); $nNumLines = count($aStrParts); for($i = 0; $i < $nNumLines; $i++) { /* if longer than 76 adds a soft-line break */ if(strlen($aStrParts[$i]) > 76) $aStrParts[$i] = preg_replace("~((.){73,76}((=[0-9A-Fa-f]{2})|([^=]{0,3})))~", "1=n", $aStrParts[$i]); } return(implode("rn", $aStrParts)); } ?>