Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

quoted_printable_decode

(PHP 3 >= 3.0.6, PHP 4, PHP 5)

quoted_printable_decode --  Раскодирует строку, закодированную методом quoted printable

Описание

string quoted_printable_decode ( string str )

Возращает строку, полученную декодированием str методом quoted printable. Эта функция подобна функции imap_qprint(), но не требует для своей работы модуля IMAP.



quotemeta> <printf
Last updated: Fri, 26 Jan 2007
 
add a note add a note User Contributed Notes
quoted_printable_decode
ludwig at gramberg-webdesign dot de
24-Sep-2007 12:13
my approach for quoted printable encode using the stream converting abilities

<?php
/**
 * @param string $str
 * @return string
 * */
function quoted_printable_encode($str) {
   
$fp = fopen('php://temp', 'w+');
   
stream_filter_append($fp, 'convert.quoted-printable-encode');
   
fwrite($fp, $str);   
   
fseek($fp, 0);
   
$result = '';
    while(!
feof($fp))
       
$result .= fread($fp, 1024);
   
fclose($fp);
    return
$result;
}
?>
roelof
24-Jul-2007 07:06
I modified the below version of legolas558 at users dot sausafe dot net and added a wrapping option.

<?php
/**
 *    Codeer een String naar zogenaamde 'quoted printable'. Dit type van coderen wordt
 *    gebruikt om de content van 8 bit e-mail berichten als 7 bits te versturen.
 *
 *    @access public
 *    @param string    $str    De String die we coderen
 *    @param bool      $wrap   Voeg linebreaks toe na 74 tekens?
 *    @return string
 */

function quoted_printable_encode($str, $wrap=true)
{
   
$return = '';
   
$iL = strlen($str);
    for(
$i=0; $i<$iL; $i++)
    {
       
$char = $str[$i];
        if(
ctype_print($char) && !ctype_punct($char)) $return .= $char;
        else
$return .= sprintf('=%02X', ord($char));
    }
    return (
$wrap === true)
        ?
wordwrap($return, 74, " =\n")
        :
$return;
}

?>
legolas558 at users dot sausafe dot net
21-Feb-2007 11:09
As soletan at toxa dot de reported, that function is very bad and does not provide valid enquoted printable strings. While using it I saw spam agents marking the emails as QP_EXCESS and sometimes the email client did not recognize the header at all; I really lost time :(. This is the new version (we use it in the Drake CMS core) that works seamlessly:

<?php

//L: note $encoding that is uppercase
//L: also your PHP installation must have ctype_alpha, otherwise write it yourself
function quoted_printable_encode($string, $encoding='UTF-8') {
// use this function with headers, not with the email body as it misses word wrapping
      
$len = strlen($string);
      
$result = '';
      
$enc = false;
       for(
$i=0;$i<$len;++$i) {
       
$c = $string[$i];
        if (
ctype_alpha($c))
           
$result.=$c;
        else if (
$c==' ') {
           
$result.='_';
           
$enc = true;
        } else {
           
$result.=sprintf("=%02X", ord($c));
           
$enc = true;
        }
       }
      
//L: so spam agents won't mark your email with QP_EXCESS
      
if (!$enc) return $string;
       return
'=?'.$encoding.'?q?'.$result.'?=';
}

I hope it helps ;)

?>
soletan at toxa dot de
20-Feb-2007 03:54
Be warned! The method below for encoding text does not work as requested by RFC1521!

Consider a line consisting of 75 'A' and a single
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571