note 72972 added to function.quoted-printable-decode
| From: | MagicalTux at ookoo dot org | Date: | Tue, 06 Feb 2007 11:44:15 +0000 |
| Subject: | note 72972 added to function.quoted-printable-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-122916@lists.php.net to get a copy of this message | ||
I checked Thomas Pequet / Memotoo.com's quoted_printable_encode() function, and it's
rather non-respective to standards...
Here's my own, fixed version :
<?php
function quoted_printable_encode($string, $linelen = 0, $linebreak="=\r\n", $breaklen = 0,
$encodecrlf = false) {
// Quoted printable encoding is rather simple.
// Each character in the string $string should be encoded if:
// Character code is <0x20 (space)
// Character is = (as it has a special meaning: 0x3d)
// Character is over ASCII range (>=0x80)
$len = strlen($string);
$result = '';
for($i=0;$i<$len;$i++) {
if ($linelen >= 76) { // break lines over 76 characters, and put special QP
linebreak
$linelen = $breaklen;
$result.= $linebreak;
}
$c = ord($string[$i]);
if (($c==0x3d) || ($c>=0x80) || ($c<0x20)) { // in this case, we encode...
if ((($c==0x0A) || ($c==0x0D)) && (!$encodecrlf)) { // but not for
linebreaks
$result.=chr($c);
$linelen = 0;
continue;
}
$result.='='.str_pad(strtoupper(dechex($c)), 2, '0');
$linelen += 3;
continue;
}
$result.=chr($c); // normal characters aren't encoded
$linelen++;
}
return $result;
}
$test = 'This is a test !! héhéhé ....'."\r\n";
$test.= 'You can write really long pieces of text without having to worry about mail transfert.
Quoted printable supports special way to handle such lines, by instering an escaped linebreak. This
linebreak, once converted back to 8bit, will disappear.';
echo quoted_printable_encode(utf8_encode($test))."\r\n";
?>
By default, the function encodes text to be used as a quoted-printable-encoded body, however by
tweaking the parameters, you can get subject-header encoding and stuff like that.
----
Server IP: 195.221.21.36
Probable Submitter: 62.73.5.156
----
Manual Page -- http://www.php.net/manual/en/function.quoted-printable-decode.php
Edit -- https://master.php.net/note/edit/72972
Del: integrated -- https://master.php.net/note/delete/72972/integrated
Del: useless -- https://master.php.net/note/delete/72972/useless
Del: bad code -- https://master.php.net/note/delete/72972/bad+code
Del: spam -- https://master.php.net/note/delete/72972/spam
Del: non-english -- https://master.php.net/note/delete/72972/non-english
Del: in docs -- https://master.php.net/note/delete/72972/in+docs
Del: other reasons-- https://master.php.net/note/delete/72972
Reject -- https://master.php.net/note/reject/72972
Search -- https://master.php.net/manage/user-notes.php