简体   繁体   中英

PHP UTF-8 file naming (Persian name)

I use the following code to build folder:

$dir = 'فارسی';
mkdir($dir);

But the created folder name converted to ظپط§ط±ط³غŒ


This problem also exists in the upload files. I uploaded the فارسی.jpg but it converted to ظپط§ط±ط³غŒ.jpg


This problem only exists on the local host. (I use windows 8 - xampp)

For Windows, the solution is to convert filename / folder name to Windows-1252 encoding:

$dir = 'فارسی';
$dir = iconv(mb_detect_encoding($dir, "auto"), 'Windows-1252', $string);
mkdir($dir);

I believe that is a reason why the error occcured on localhost and never on server: The server probably uses Linux.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM