Portrety Uliczne Nieznajomych - zobacz wyjątkową galerię portretów z warszawskich ulic
ZALOGUJ SIĘ
login:
hasło:
przypomnij hasło
załóż konto użytkownika
(i zobacz kilka porad gratis)
   
WYSZUKIWARKA I DZIAŁY
całe porady  tytuły
zaznacz działy do przeszukania
(brak wyboru = wszystkie działy)
PHP
MySQL >
PostgreSQL
SQLite
Perl
Java
XML
XSLT
XPath
WML
SVG
RegExp
Wyszukiwarki
Ochrona
VBScript
Google Plus
XHTML/CSS
JavaScript
Grafika
Flash
Photoshop
Windows
Linux
Bash
Apache
Procmail
E-biznes
Explorer
Opera
Firefox
Inne porady
   
KURSY, DOKUMENTACJE
Własne:
XHTML/CSS
JavaScript
ActionScript
WML, RSS, SSI
Pozostałe:
PHP
MySQL
Java API
więcej...
   
użytkowników online: 43
W CZYM MOGĘ POMÓC?


   
OPINIE UŻYTKOWNIKÓW
W takich dniach, jak ten, nie żałuję, że wykupiłem abonament. Korzystam z porad na tych stronach nawet kilkanaście razy w tygodniu i dzięki nim prace nad stronami dla klientów idą mi o wiele szybciej, a strony wyglądają bardziej profesjonalnie. Nie wiem, jak mogłem wcześniej pracować bez dostępu do porad w tym serwisie!

Wojciech Miszkiewicz

   
GALERIA FOTOGRAFII
   
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net

[Spis] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [X] [W] [Z]

quoted_printable_decode

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

quoted_printable_decode --  Convert a quoted-printable string to an 8 bit string

Description

string quoted_printable_decode ( string str )

This function returns an 8-bit binary string corresponding to the decoded quoted printable string (according to RFC2045, section 6.7, not RFC2821, section 4.5.2, so additional periods are not stripped from the beginning of line). This function is similar to imap_qprint(), except this one does not require the IMAP module to work.




User Contributed Notes

steffen dot weber at computerbase dot de
22-Jul-2005 11:08

As the two digit hexadecimal representation SHOULD be in uppercase you want to use "=%02X" (uppercase X) instead of "=%02x" as the first argument to sprintf().


bendi at interia dot pl
29-Mar-2005 11:08

This function appeared twice already and in both versions it's got error in rule replacing chunk_split, because it misses the last line in encoded text if it's shorter than 73 characters.

My solution (got rid of replace_callback)
<?
function quoted_printable_encode( $sString ) {
  
/*instead of replace_callback i used <b>e</b> modifier for regex rule, which works as eval php function*/
  
$sString = preg_replace( '/[^\x21-\x3C\x3E-\x7E\x09\x20]/e', 'sprintf( "=%02x", ord ( "$0" ) ) ;'$sString );
  
/*now added to this rule one or more chars which lets last line to be matched and included in results*/
  
preg_match_all( '/.{1,73}([^=]{0,3})?/', $sString, $aMatch );
   return
implode( '=' . CR, $aMatch[0] );
}

?>


dmitry at koterov dot ru
19-Feb-2005 02:26

Previous comment has a bug: encoding of short test does not work because of incorrect usage of preg_match_all(). Have somebody read it at all? :-)

Correct version (seems), with additional imap_8bit() function emulation:

if (!function_exists('imap_8bit')) {
 function imap_8bit($text) {
   return quoted_printable_encode($text);
 }
}

function quoted_printable_encode_character ( $matches ) {
   $character = $matches[0];
   return sprintf ( '=%02x', ord ( $character ) );
}

// based on http://www.freesoft.org/CIE/RFC/1521/6.htm
function quoted_printable_encode ( $string ) {
   // rule #2, #3 (leaves space and tab characters in tact)
   $string = preg_replace_callback (
     '/[^\x21-\x3C\x3E-\x7E\x09\x20]/',
     'quoted_printable_encode_character',
     $string
   );
   $newline = "=\r\n"; // '=' + CRLF (rule #4)
   // make sure the splitting of lines does not interfere with escaped characters
   // (chunk_split fails here)
   $string = preg_replace ( '/(.{73}[^=]{0,3})/', '$1'.$newline, $string);
   return $string;
}


drm at melp dot nl
09-Feb-2005 12:32

A easier, improved way of encoding for quoted-printable transfer:

------
function quoted_printable_encode_character ( $matches ) {
   $character = end ( $matches );
   return sprintf ( '=%02x', ord ( $character ) );
}

// based on http://www.freesoft.org/CIE/RFC/1521/6.htm
function quoted_printable_encode ( $string ) {
   // rule #2, #3 (leaves space and tab characters in tact)
   $string = preg_replace_callback (
     '/[^\x21-\x3C\x3E-\x7E\x09\x20]/',
     'quoted_printable_encode_character',
     $string
   );
  
   $newline = "=\r\n"; // '=' + CRLF (rule #4)

   // make sure the splitting of lines does not interfere with escaped characters
   // (chunk_split fails here)
   preg_match_all ( '/.{73}([^=]{0,3})/', $string, $match ); // Rule #1
   return implode ( $newline, $match[0] );
}
-----


tamas dot tompa at kirowski dot com
20-Feb-2004 04:46

i have found a bug in pob at medienrecht dot NOSPAM dot org
's qp_enc function. in quoted printable messages need to convert the first pont in the lines too...
here is the fixed code:

function qp_enc( $input = "", $line_max = 76, $space_conv = false ) {

   $hex = array('0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F');
   $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
   $eol = "\r\n";
   $escape = "=";
   $output = "";

       while( list(, $line) = each($lines) ) {
               //$line = rtrim($line); // remove trailing white
space -> no =20\r\n necessary
               $linlen = strlen($line);
               $newline = "";
               for($i = 0; $i < $linlen; $i++) {
                       $c = substr( $line, $i, 1 );
                       $dec = ord( $c );
                       if ( ( $i == 0 ) && ( $dec == 46 ) ) { //
convert first point in the line into =2E
                               $c = "=2E";
                       }
                       if ( $dec == 32 ) {
                               if ( $i == ( $linlen - 1 ) ) { // convert
 space at eol only
                                       $c = "=20";
                               } else if ( $space_conv ) {
                                       $c = "=20";
                               }
                       } elseif ( ($dec == 61) || ($dec < 32 ) ||
($dec > 126) ) { // always encode "\t", which is *not* required
                               $h2 = floor($dec/16);
                               $h1 = floor($dec%16);
                               $c = $escape.$hex["$h2"].$hex["$h1"];
                       }
                       if ( (strlen($newline) + strlen($c)) >=
$line_max ) { // CRLF is not counted
                               $output .= $newline.$escape.$eol; //
soft line break; " =\r\n" is okay
                               $newline = "";
                               // check if newline first character will
be point or not
                               if ( $dec == 46 ) {
                                       $c = "=2E";
                               }
                       }
                       $newline .= $c;
               } // end of for
               $output .= $newline.$eol;
       } // end of while
       return trim($output);
}


pinkpanther at swissonline dot ch
05-Jan-2003 12:31

Sorry, above I mixed up QP-Decode and UrlDecode, the example I gave above is in fact UrlDecode:

function UrlDecode($string) {
return preg_replace("/%([0-9A-Fa-f]{2})/e", "chr(hexdec('\\1'))", $string);
}

f.e. replaces '%3F' with '?'

Quoted-printable would be:

function qp_decode($string) {
return preg_replace("/=([0-9A-F]{2})/e", "chr(hexdec('\\1'))", $string);
}

f.e. replaces '=20' with ' '


pob at medienrecht dot NOSPAM dot org
18-Jul-2001 10:06

If you do not have access to imap_* and do not want to use

 

 
  © 1996-2012 & Reporter.plmiejscao serwisieabonamentwarunki korzystaniaRSSkontakt