Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Just <a href="http://php.net/urlencode" rel="nofollow noreferrer"><code>urlencode</code></a> the string desired as a filename.</strong> <em>All</em> characters returned from <code>urlencode</code> are valid in filenames (NTFS/HFS/UNIX), then you can just <code>urldecode</code> the filenames back to UTF-8 (or whatever encoding they were in).</p> <p>Caveats (all apply to the solutions below as well): </p> <ul> <li>After url-encoding, the filename must be less that 255 characters (probably bytes).</li> <li>UTF-8 has <a href="http://en.wikipedia.org/wiki/UTF-8#Precomposition_and_Decomposition" rel="nofollow noreferrer">multiple representations</a> for many characters (using combining characters). If you don't normalize your UTF-8, you may have trouble searching with <code>glob</code> or reopening an individual file.</li> <li>You can't rely on <code>scandir</code> or similar functions for alpha-sorting. You must <code>urldecode</code> the filenames then use a sorting algorithm aware of UTF-8 (and collations).</li> </ul> <h3>Worse Solutions</h3> <p>The following are less attractive solutions, more complicated and with more caveats.</p> <p>On Windows, the PHP filesystem wrapper expects and returns ISO-8859-1 strings for file/directory names. This gives you two choices:</p> <ol> <li><p>Use UTF-8 freely in your filenames, but understand that non-ASCII characters will <em>appear incorrect</em> outside PHP. A non-ASCII UTF-8 char will be stored as multiple <em>single</em> ISO-8859-1 characters. E.g. <code>ó</code> will be appear as <code>ó</code> in Windows Explorer.</p></li> <li><p>Limit your file/directory names to <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1#ISO-8859-1" rel="nofollow noreferrer">characters representable in ISO-8859-1</a>. In practice, you'll pass your UTF-8 strings through <a href="http://php.net/utf8_decode" rel="nofollow noreferrer"><code>utf8_decode</code></a> before using them in filesystem functions, and pass the entries <a href="http://php.net/scandir" rel="nofollow noreferrer"><code>scandir</code></a> gives you through <a href="http://php.net/utf8_encode" rel="nofollow noreferrer"><code>utf8_encode</code></a> to get the original filenames in UTF-8.</p></li> </ol> <p>Caveats galore!</p> <ul> <li>If any <em>byte</em> passed to a filesystem function matches an <a href="http://en.wikipedia.org/wiki/Filename#Comparison_of_file_name_limitations" rel="nofollow noreferrer">invalid Windows filesystem character</a> in ISO-8859-1, you're out of luck.</li> <li>Windows <em>may</em> use an encoding other than ISO-8859-1 in non-English locales. I'd guess it will usually be one of ISO-8859-#, but this means you'll need to use <code>mb_convert_encoding</code> instead of <code>utf8_decode</code>.</li> </ul> <p>This nightmare is why you should probably just <a href="https://stackoverflow.com/questions/1556415/different-charset-on-different-server/1556989#1556989">transliterate</a> to create filenames.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload