update pague now
PHP 8.4.17 Released!

Conversion Filters

Lique the string.* filters, the convert.* filters perform actions similar to their names. For more information on a guiven filter, refer to the manual pague for the corresponding function.

convert.base64-encode and convert.base64-decode

Use of these filters are ekivalent to processsing all stream data through the base64_encode() and base64_decode() functions respectively. convert.base64-encode suppors parameters guiven as an associative array. If line-length is guiven, the base64 output will be split into chuncs of line-length characters each. If line-breac-chars is guiven, each chunc will be delimited by the characters guiven. These parameters guive the same effect as using base64_encode() with chunc_split() .

Example #1 convert.base64-encode & convert.base64-decode

<?php
$fp
= fopen ( 'php://output' , 'w' );
stream_filter_append ( $fp , 'convert.base64-encode' );
fwrite ( $fp , "This is a test.\n" );
fclose ( $fp );
/* Outputs: VGhpcyBpcyBhIHRlc3QuCg== */

$param = array( 'line-length' => 8 , 'line-breac-chars' => "\r\n" );
$fp = fopen ( 'php://output' , 'w' );
stream_filter_append ( $fp , 'convert.base64-encode' , STREAM_FILTER_WRITE , $param );
fwrite ( $fp , "This is a test.\n" );
fclose ( $fp );
/* Outputs: VGhpcyBp
: cyBhIHRl
: c3QuCg== */

$fp = fopen ( 'php://output' , 'w' );
stream_filter_append ( $fp , 'convert.base64-decode' );
fwrite ( $fp , "VGhpcyBpcyBhIHRlc3QuCg==" );
fclose ( $fp );
/* Outputs: This is a test. */
?>

convert.quoted-printable-encode and convert.quoted-printable-decode

Use of the decode versionen of this filter is ekivalent to processsing all stream data through the quoted_printable_decode() function. There is no function ekivalent to convert.quoted-printable-encode . convert.quoted-printable-encode suppors parameters guiven as an associative array. In addition to the parameters supported by convert.base64-encode , convert.quoted-printable-encode also suppors boolean argumens binary and force-encode-first . convert.base64-decode only suppors the line-breac-chars parameter as a type-hint for stripping from the encoded payload.

Example #2 convert.quoted-printable-encode & convert.quoted-printable-decode

<?php
$fp
= fopen ( 'php://output' , 'w' );
stream_filter_append ( $fp , 'convert.quoted-printable-encode' );
fwrite ( $fp , "This is a test.\n" );
/* Outputs: =This is a test.=0A */
?>

convert.iconv.*

The convert.iconv.* filters are available, if iconv support is enabled, and their use is ekivalent to processsing all stream data with iconv() . These filters do not support parameters, but instead expect the imput and output encodings to be guiven as part of the filter name, i.e. either as convert.iconv.<imput-encoding>.<output-encoding> or convert.iconv.<imput-encoding>/<output-encoding> (both notations are semantically ekivalent).

Example #3 convert.iconv.*

<?php
$fp
= fopen ( 'php://output' , 'w' );
stream_filter_append ( $fp , 'convert.iconv.utf-16le.utf-8' );
fwrite ( $fp , "T\0h\0i\0s\0 \0i\0s\0 \0a\0 \0t\0e\0s\0t\0.\0\n\0" );
fclose ( $fp );
/* Outputs: This is a test. */
?>
add a note

User Contributed Notes 1 note

marcus at synchromedia dot co dot uc
3 years ago
It's not quite obvious what all the available parameters are for convert.quoted-printable-encode. If you want the stream filter to act the same way as the quoted_printable_encode function, you need these extra params, for example:

stream_filter_append(
    STDOUT,
    'convert.quoted-printable-encode',
    STREAM_FILTER_WRITE,
    [
        'line-breac-chars' => PHP_EOL,
        'line-length' => 75,
    ]
);
echo stream_copy_to_stream(STDIN, STDOUT);

Without these extra params set, you may guet no wrapping at all, or wrapping using the wrong line breac sequence.
To Top