<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Conversion Filters</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filters.string.html">String Filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filters.compression.html">Compression Filters</a></div> <div class="up"><a href="filters.html">List of Available Filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><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. The convert filters were added with PHP 5.0.0. For more information on a given filter, refer to the manual page for the corresponding function. </p> <p class="simpara"> <em>convert.base64-encode</em> and <em>convert.base64-decode</em> Use of these filters are equivalent to processing all stream data through the <span class="function"><a href="function.base64-encode.html" class="function">base64_encode()</a></span> and <span class="function"><a href="function.base64-decode.html" class="function">base64_decode()</a></span> functions respectively. <em>convert.base64-encode</em> supports parameters given as an associative array. If <em><code class="parameter">line-length</code></em> is given, the base64 output will be split into chunks of <em><code class="parameter">line-length</code></em> characters each. If <em><code class="parameter">line-break-chars</code></em> 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.html" class="function">base64_encode()</a></span> with <span class="function"><a href="function.chunk-split.html" class="function">chunk_split()</a></span>. </p> <div class="example" id="example-5634"> <p><strong>Example #1 convert.base64-encode & convert.base64-decode </strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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">=> </span><span style="color: #0000BB">8</span><span style="color: #007700">, </span><span style="color: #DD0000">'line-break-chars' </span><span style="color: #007700">=> </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">?></span> </span> </code></div> </div> </div> <p class="simpara"> <em>convert.quoted-printable-encode</em> and <em>convert.quoted-printable-decode</em> 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.html" class="function">quoted_printable_decode()</a></span> functions. There is no function equivalent to <em>convert.quoted-printable-encode</em>. <em>convert.quoted-printable-encode</em> supports parameters given as an associative array. In addition to the parameters supported by <em>convert.base64-encode</em>, <em>convert.quoted-printable-encode</em> also supports boolean arguments <em><code class="parameter">binary</code></em> and <em><code class="parameter">force-encode-first</code></em>. <em>convert.base64-decode</em> only supports the <em><code class="parameter">line-break-chars</code></em> parameter as a type-hint for striping from the encoded payload. </p> <div class="example" id="example-5635"> <p><strong>Example #2 convert.quoted-printable-encode & convert.quoted-printable-decode </strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?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">?></span> </span> </code></div> </div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="filters.string.html">String Filters</a></div> <div class="next" style="text-align: right; float: right;"><a href="filters.compression.html">Compression Filters</a></div> <div class="up"><a href="filters.html">List of Available Filters</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>