- function QPencode($str)
- {
- DEFINE('CRLF', "\r\n");
-
- $lines = preg_split("/\r?\n/", $str);
- $out = '';
-
- foreach ($lines as $line)
- {
- $newpara = '';
-
- for ($j = 0; $j <= strlen($line) - 1; $j++)
- {
- $char = substr ( $line, $j, 1 );
- $ascii = ord ( $char );
-
- if ( $ascii < 32 || $ascii == 61 || $ascii > 126 )
- {
- $char = '=' . strtoupper ( dechex( $ascii ) );
- }
-
- if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 76 )
- {
- $out .= $newpara . '=' . CRLF; $newpara = '';
- }
- $newpara .= $char;
- }
- $out .= $newpara . $char;
- }
- return trim ( $out );
- }
-
- function QPdecode( $str )
- {
- $out = preg_replace('/=\r?\n/', '', $str);
- $out = preg_replace('/=([A-F0-9]{2})/e', chr( hexdec ('\\1' ) ), $out);
-
- return trim($out);
- }
-
- ?>
function QPencode($str)
{
DEFINE('CRLF', "\r\n");
$lines = preg_split("/\r?\n/", $str);
$out = '';
foreach ($lines as $line)
{
$newpara = '';
for ($j = 0; $j <= strlen($line) - 1; $j++)
{
$char = substr ( $line, $j, 1 );
$ascii = ord ( $char );
if ( $ascii < 32 || $ascii == 61 || $ascii > 126 )
{
$char = '=' . strtoupper ( dechex( $ascii ) );
}
if ( ( strlen ( $newpara ) + strlen ( $char ) ) >= 76 )
{
$out .= $newpara . '=' . CRLF; $newpara = '';
}
$newpara .= $char;
}
$out .= $newpara . $char;
}
return trim ( $out );
}
function QPdecode( $str )
{
$out = preg_replace('/=\r?\n/', '', $str);
$out = preg_replace('/=([A-F0-9]{2})/e', chr( hexdec ('\\1' ) ), $out);
return trim($out);
}
?>