title: How do I remove accents from characters in a PHP string?
body: <p>I'm attempting to remove accents from characters in PHP string as the first step to making the string usable in a URL.</p>
  
  <p>I'm using the following code:</p>
  
  <pre><code>$input = "Fóø Bår";
  
  setlocale(LC_ALL, "en_US.utf8");
  $output = iconv("utf-8", "ascii//TRANSLIT", $input);
  
  print($output);
  </code></pre>
  
  <p>The output I would expect would be something like this:</p>
  
  <pre><code>F'oo Bar
  </code></pre>
  
  <p>However, instead of the accented characters being transliterated they are replaced with question marks:</p>
  
  <pre><code>F?? B?r
  </code></pre>
  
  <p>Everything I can find online indicates that setting the locale will fix this problem, however I'm already doing this.  I've already checked the following details:</p>
  
  <ol>
  <li>The locale I am setting is supported by the server (included in the list produced by <code>locale -a</code>)</li>
  <li>The source and target encodings (UTF-8 and ASCII) are supported by the server's version of iconv (included in the list produced by <code>iconv -l</code>)</li>
  <li>The input string is UTF-8 encoded (verified using PHP's <code>mb_check_encoding</code> function, as suggested in the <a href="https://stackoverflow.com/questions/1017599/how-do-i-remove-accents-from-characters-in-a-php-string/1018160#1018160">answer by mercator</a>)</li>
  <li>The call to <code>setlocale</code> is successful (it returns <code>'en_US.utf8'</code> rather than <code>FALSE</code>)</li>
  </ol>
  
  <hr>
  
  <h2>The cause of the problem:</h2>
  
  <p>The server is using the wrong implementation of iconv.  It has the <strong>glibc</strong> version instead of the required <strong>libiconv</strong> version.</p>
  
  <blockquote>
    <p>Note that the iconv function on some systems may not work as you expect. In such case, it'd be a good idea to install the GNU libiconv library. It will most likely end up with more consistent results.<br>
    <em>– <a href="http://www.php.net/manual/en/intro.iconv.php" rel="noreferrer">PHP manual's introduction to iconv</a></em></p>
  </blockquote>
  
  <p>Details about the iconv implementation that is used by PHP are included in the output of the <code>phpinfo</code> function.</p>
  
  <p>(I'm not able to re-compile PHP with the correct iconv library on the server I'm working with for this project so the answer I've accepted below is the one that was most useful for removing accents without iconv support.)</p>