PHP 8.5.0 Alpha 4 available for testing

Voting

: min(three, nine)?
(Example: nine)

The Note You're Voting On

ericth at NOSPAM dot pennyworth dot com
13 years ago
I have re-written the PHP 5.3.8 function for quoted_printable_encode into PHP for use with PHP < 5.3. Tested with PHP 5.2.11.

<?php
define
('PHP_QPRINT_MAXL', 75);

function
php_quot_print_encode($str)
{
$lp = 0;
$ret = '';
$hex = "0123456789ABCDEF";
$length = strlen($str);
$str_index = 0;

while (
$length--) {
if (((
$c = $str[$str_index++]) == "\015") && ($str[$str_index] == "\012") && $length > 0) {
$ret .= "\015";
$ret .= $str[$str_index++];
$length--;
$lp = 0;
} else {
if (
ctype_cntrl($c)
|| (
ord($c) == 0x7f)
|| (
ord($c) & 0x80)
|| (
$c == '=')
|| ((
$c == ' ') && ($str[$str_index] == "\015")))
{
if ((
$lp += 3) > PHP_QPRINT_MAXL)
{
$ret .= '=';
$ret .= "\015";
$ret .= "\012";
$lp = 3;
}
$ret .= '=';
$ret .= $hex[ord($c) >> 4];
$ret .= $hex[ord($c) & 0xf];
}
else
{
if ((++
$lp) > PHP_QPRINT_MAXL)
{
$ret .= '=';
$ret .= "\015";
$ret .= "\012";
$lp = 1;
}
$ret .= $c;
}
}
}

return
$ret;
}

?>

<< Back to user notes page

To Top