<!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>HTTP Input and Output</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mbstring.ja-basic.html">Basics of Japanese multi-byte encodings</a></div> <div class="next" style="text-align: right; float: right;"><a href="mbstring.supported-encodings.html">Supported Character Encodings</a></div> <div class="up"><a href="book.mbstring.html">Multibyte String</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mbstring.http" class="chapter"> <h1>HTTP Input and Output</h1> <p class="para"> HTTP input/output character encoding conversion may convert binary data also. Users are supposed to control character encoding conversion if binary data is used for HTTP input/output. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> In PHP 4.3.2 or earlier versions, there was a limitation in this functionality that <em>mbstring</em> does not perform character encoding conversion in POST data if the <em>enctype</em> attribute in the <em>form</em> element is set to <em>multipart/form-data</em>. So you have to convert the incoming data by yourself in this case if necessary. </p> <p class="para"> Beginning with PHP 4.3.3, if <em>enctype</em> for HTML form is set to <em>multipart/form-data</em> and <em>mbstring.encoding_translation</em> is set to On in <var class="filename">php.ini</var> the POST'ed variables and the names of uploaded files will be converted to the internal character encoding as well. However, the conversion isn't applied to the query keys. </p> </p></blockquote> <p class="para"> <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> HTTP Input </span> <p class="para"> There is no way to control HTTP input character conversion from a PHP script. To disable HTTP input character conversion, it has to be done in <var class="filename">php.ini</var>. <div class="example" id="example-2696"> <p><strong>Example #1 Disable HTTP input conversion in <var class="filename">php.ini</var> </strong></p> <div class="example-contents"> <div class="php.inicode"><pre class="php.inicode">;; Disable HTTP Input conversion mbstring.http_input = pass ;; Disable HTTP Input conversion (PHP 4.3.0 or higher) mbstring.encoding_translation = Off</pre> </div> </div> </div> </p> <p class="para"> When using PHP as an Apache module, it is possible to override those settings in each Virtual Host directive in <var class="filename">httpd.conf</var> or per directory with <var class="filename">.htaccess</var>. Refer to the <a href="configuration.html" class="link">Configuration</a> section and Apache Manual for details. </p> </li> <li class="listitem"> <span class="simpara"> HTTP Output </span> <p class="para"> There are several ways to enable output character encoding conversion. One is using <var class="filename">php.ini</var>, another is using <span class="function"><a href="function.ob-start.html" class="function">ob_start()</a></span> with <span class="function"><a href="function.mb-output-handler.html" class="function">mb_output_handler()</a></span> as the <em>ob_start</em> callback function. </p> </li> </ul> </p> <p class="para"> <div class="example" id="example-2697"> <p><strong>Example #2 <var class="filename">php.ini</var> setting example</strong></p> <div class="example-contents"> <div class="cdata"><pre> ;; Enable output character encoding conversion for all PHP pages ;; Enable Output Buffering output_buffering = On ;; Set mb_output_handler to enable output conversion output_handler = mb_output_handler </pre></div> </div> </div> </p> <p class="para"> <div class="example" id="example-2698"> <p><strong>Example #3 Script example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// Enable output character encoding conversion only for this page<br /><br />// Set HTTP output character encoding to SJIS<br /></span><span style="color: #0000BB">mb_http_output</span><span style="color: #007700">(</span><span style="color: #DD0000">'SJIS'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Start buffering and specify "mb_output_handler" as<br />// callback function<br /></span><span style="color: #0000BB">ob_start</span><span style="color: #007700">(</span><span style="color: #DD0000">'mb_output_handler'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mbstring.ja-basic.html">Basics of Japanese multi-byte encodings</a></div> <div class="next" style="text-align: right; float: right;"><a href="mbstring.supported-encodings.html">Supported Character Encodings</a></div> <div class="up"><a href="book.mbstring.html">Multibyte String</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>