英語でphpを使用してディレクトリを作成しようとしていますが、機能しています。しかし、ヘブライ語で試してみると、次のようにフォルダがギブリッシュで作成されます。׳׳©׳—׳§ ׳©׳•׳׳~</p>
どうすれば修正できますか?ありがとう
PHP has some Unicode support when dealing with strings, but internally PHP's string type is single-byte and does not support multibyte encodings. If you save your PHP file in UTF-8 format, you can output strings in UTF-8 with the proper HTTP encodings, but many of PHP's functions don't support multi-byte strings. There are some that do, but still most that do not.
I looked around in the PHP source and most of the filesystem functions like mkdir
are not Unicode aware. They operate on single byte strings which is why you get the ASCII gibberish when you try to create a directory.
You might try calling setlocale
and setting it to he_IL
before calling mkdir
to see if this makes any difference.
For more information:
A string is series of characters, where a character is the same as a byte. This means that PHP only supports a 256-character set, and hence does not offer native Unicode support. See details of the string type.
The details talk more about different encodings, functions that are multi-byte aware and different behavior based on whether or not Zend Multibyte support is enabled in PHP and how saving your files in different encodings effects strings within PHP.
Unfortunately at this time, I don't believe you will be able to create a directory containing multi-byte strings in PHP directly.
Internally, the function mkdir
calls this function mkdir in file.c which calls _php_stream_mkdir which uses the plain files wrapper
to call php_mkdir_ex to ultimately create the directory using virtual_mkdir that uses the C mkdir function to create the directory.
I think by the time it calls mkdir to create the directory on the file-system, all encodings have been lost and it is treated as a single-byte char * string.
mb_convert_encoding を使用して、名前 (文字列) を UTF-8 から ISO-8859-8 に変換します。PHP 7 と Windows 10 でテストしました。
OSのエンコーディングシステムがこれらの文字をサポートしていない限り、基本的にはできません。ヘブライ語も拡張 UTF-8 パッケージの一部でなければなりませんよね?
たとえば Windows では、デフォルトのコードページは iso-8859-1 で、ヘブライ語はありません。
新しいWindowsバージョンではファイル名にすべてのUnicode文字が許可されているため、UTF-8に切り替えるとうまくいくと思いますが、あまりお勧めしません