<!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>Convert string to requested character encoding</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.iconv-substr.html">iconv_substr</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ob-iconv-handler.html">ob_iconv_handler</a></div> <div class="up"><a href="ref.iconv.html">iconv Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.iconv" class="refentry"> <div class="refnamediv"> <h1 class="refname">iconv</h1> <p class="verinfo">(PHP 4 >= 4.0.5, PHP 5)</p><p class="refpurpose"><span class="refname">iconv</span> — <span class="dc-title">Convert string to requested character encoding</span></p> </div> <div class="refsect1 description" id="refsect1-function.iconv-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">string</span> <span class="methodname"><strong>iconv</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$in_charset</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$out_charset</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span> )</div> <p class="para rdfs-comment"> Performs a character set conversion on the string <em><code class="parameter">str</code></em> from <em><code class="parameter">in_charset</code></em> to <em><code class="parameter">out_charset</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.iconv-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">in_charset</code></em></span> <dd> <p class="para"> The input charset. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">out_charset</code></em></span> <dd> <p class="para"> The output charset. </p> <p class="para"> If you append the string <em>//TRANSLIT</em> to <em><code class="parameter">out_charset</code></em> transliteration is activated. This means that when a character can't be represented in the target charset, it can be approximated through one or several similarly looking characters. If you append the string <em>//IGNORE</em>, characters that cannot be represented in the target charset are silently discarded. Otherwise, <em><code class="parameter">str</code></em> is cut from the first illegal character and an <strong><code>E_NOTICE</code></strong> is generated. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">str</code></em></span> <dd> <p class="para"> The string to be converted. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.iconv-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns the converted string or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 examples" id="refsect1-function.iconv-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2480"> <p><strong>Example #1 <span class="function"><strong>iconv()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$text </span><span style="color: #007700">= </span><span style="color: #DD0000">"This is the Euro symbol '€'."</span><span style="color: #007700">;<br /><br />echo </span><span style="color: #DD0000">'Original : '</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">, </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'TRANSLIT : '</span><span style="color: #007700">, </span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ISO-8859-1//TRANSLIT"</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'IGNORE : '</span><span style="color: #007700">, </span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ISO-8859-1//IGNORE"</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br />echo </span><span style="color: #DD0000">'Plain : '</span><span style="color: #007700">, </span><span style="color: #0000BB">iconv</span><span style="color: #007700">(</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #007700">, </span><span style="color: #DD0000">"ISO-8859-1"</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">), </span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output something similar to:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Original : This is the Euro symbol '€'. TRANSLIT : This is the Euro symbol 'EUR'. IGNORE : This is the Euro symbol ''. Plain : Notice: iconv(): Detected an illegal character in input string in .\iconv-example.php on line 7 This is the Euro symbol ' </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.iconv-substr.html">iconv_substr</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.ob-iconv-handler.html">ob_iconv_handler</a></div> <div class="up"><a href="ref.iconv.html">iconv Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>