<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/filters.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'filters.convert.php',
    1 => 'Conversion Filters',
    2 => 'Conversion Filters',
  ),
  'up' => 
  array (
    0 => 'filters.php',
    1 => 'List of Available Filters',
  ),
  'prev' => 
  array (
    0 => 'filters.string.php',
    1 => 'String Filters',
  ),
  'next' => 
  array (
    0 => 'filters.compression.php',
    1 => 'Compression Filters',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'appendices/filters.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="filters.convert" class="section">
  <h2 class="title">Conversion Filters</h2>

  <p class="simpara">
   Like the string.* filters, the convert.* filters perform actions
   similar to their names.
   For more information on a given filter, refer to the manual page for
   the corresponding function.
  </p>

  <div class="section" id="filters.convert.base64">
   <h2 class="title">convert.base64-encode and convert.base64-decode</h2>
   <p class="simpara">
    Use of these filters are equivalent to processing all stream data through
    the <span class="function"><a href="function.base64-encode.php" class="function">base64_encode()</a></span> and <span class="function"><a href="function.base64-decode.php" class="function">base64_decode()</a></span>
    functions respectively.
    <code class="literal">convert.base64-encode</code> supports parameters given as
    an associative array.  If <code class="parameter">line-length</code> is given, the
    base64 output will be split into chunks of <code class="parameter">line-length</code>
    characters each.  If <code class="parameter">line-break-chars</code> is given, each
    chunk will be delimited by the characters given.  These parameters give the
    same effect as using <span class="function"><a href="function.base64-encode.php" class="function">base64_encode()</a></span> with
    <span class="function"><a href="function.chunk-split.php" class="function">chunk_split()</a></span>.
   </p>
   <div class="example" id="example-1">
    <p><strong>Example #1 
     convert.base64-encode &amp;
     convert.base64-decode
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'convert.base64-encode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs:  VGhpcyBpcyBhIHRlc3QuCg==  */<br /><br /></span><span style="color: #0000BB">$param </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'line-length' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">8</span><span style="color: #007700">, </span><span style="color: #DD0000">'line-break-chars' </span><span style="color: #007700">=&gt; </span><span style="color: #DD0000">"\r\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'convert.base64-encode'</span><span style="color: #007700">, </span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">, </span><span style="color: #0000BB">$param</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs:  VGhpcyBp<br />          :  cyBhIHRl<br />          :  c3QuCg==  */<br /><br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'convert.base64-decode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"VGhpcyBpcyBhIHRlc3QuCg=="</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs:  This is a test.  */<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </div>

  <div class="section" id="filters.covert.quoted-printable">
   <h2 class="title">convert.quoted-printable-encode and convert.quoted-printable-decode</h2>
   <p class="simpara">
    Use of the decode version of this filter is equivalent to processing all stream 
    data through the <span class="function"><a href="function.quoted-printable-decode.php" class="function">quoted_printable_decode()</a></span> function.
    There is no function equivalent to <code class="literal">convert.quoted-printable-encode</code>.
    <code class="literal">convert.quoted-printable-encode</code> supports parameters given as
    an associative array.  In addition to the parameters supported by 
    <code class="literal">convert.base64-encode</code>, <code class="literal">convert.quoted-printable-encode</code>
    also supports boolean arguments <code class="parameter">binary</code> and
    <code class="parameter">force-encode-first</code>.
    <code class="literal">convert.base64-decode</code> only supports the
    <code class="parameter">line-break-chars</code> parameter as a type-hint
    for stripping from the encoded payload.
   </p>
   <div class="example" id="example-2">
    <p><strong>Example #2 
     convert.quoted-printable-encode &amp;
     convert.quoted-printable-decode
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'convert.quoted-printable-encode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"This is a test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs:  =This is a test.=0A  */<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </div>

  <div class="section" id="filters.convert.iconv">
   <h2 class="title">convert.iconv.*</h2>
   <p class="simpara">
    The <code class="literal">convert.iconv.*</code> filters are available, if
    <a href="book.iconv.php" class="link">iconv</a> support is enabled, and their use is
    equivalent to processing all stream data with <span class="function"><a href="function.iconv.php" class="function">iconv()</a></span>.
    These filters do not support parameters, but instead expect the input and
    output encodings to be given as part of the filter name, i.e. either as
    <code class="literal">convert.iconv.&lt;input-encoding&gt;.&lt;output-encoding&gt;</code> or
    <code class="literal">convert.iconv.&lt;input-encoding&gt;/&lt;output-encoding&gt;</code>
    (both notations are semantically equivalent).
   </p>

   <div class="example" id="example-3">
    <p><strong>Example #3 convert.iconv.*</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">'convert.iconv.utf-16le.utf-8'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"T\0h\0i\0s\0 \0i\0s\0 \0a\0 \0t\0e\0s\0t\0.\0\n\0"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/* Outputs: This is a test. */<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </div>
 </div><?php manual_footer($setup); ?>