3

I want to create Arabic folders or files using PHP but I always receive strange letters when using this code `

$location  = "d:/test" ; // Your Location 

$foldername = "عربى" ; // Your Folder Name 

$path = $location . "/" . $foldername ;



if (!is_dir ( $path )) { 

    if(is_writable($location)) 
    { 
        echo $path."<br>"; 
        mkdir ($path, 0777 ); 
    } 
    else 
    { 
        die("You don't have permission to create folder"); 
    } 
} 
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
  • 2
    Does it work when you create your arabic folder by hand? – Sentencio Nov 13 '12 at 10:43
  • yes it works but with the script it gives me ط¹ط±ط¨ظ‰ – Hussein Sayed Nov 13 '12 at 10:56
  • So your path to folder is: `d:/test/ ط¹ط±ط¨ظ‰`? I don't have any experience with arabic letters. So i would print each letter to see where the special chars come from. – Sentencio Nov 13 '12 at 10:58
  • yes and i want it to be d:/test/عربى – Hussein Sayed Nov 13 '12 at 10:59
  • In your snippet there is a print statement where you can see if the path is correct. Have you checked if the folder has the correct name or did you only check the print output? Then it could be an encoding problem. – Sentencio Nov 13 '12 at 11:11
  • Maybe encoding in your PHP file is wrong? What editor are you using? – Kamil Nov 13 '12 at 11:16
  • The encoding is working good and i see the expected output work ok but the problem is in the folder itself ,the snippet creates a folder named ط¹ط±ط¨ظ‰ and the output gives me d:/test/عربى – Hussein Sayed Nov 13 '12 at 11:17
  • You might be out of luck: http://stackoverflow.com/a/2950046/13508 – Álvaro González Nov 13 '12 at 11:28
  • Is this possible in ASP.NET (Microsoft IIS)? – Kamil Nov 13 '12 at 11:34
  • I'm pretty sure PHP doesn't call the Unicode version of Windows' file system functions. You will probably have to use a COM object. – cleong Nov 13 '12 at 11:42
  • possible duplicate of [How do I use filesystem functions in PHP, using UTF-8 strings?](http://stackoverflow.com/questions/1525830/how-do-i-use-filesystem-functions-in-php-using-utf-8-strings) – Madara's Ghost Nov 13 '12 at 11:47

1 Answers1

1

Link from Álvaro G. Vicario in comment under your question says that is impossible in PHP. I think it may be possible in Microsoft ASP.NET, but im not sure. If this is very important to you - you can make some research about it and maybe switch from PHP to ASP.

Anyway, in PHP you can use urlencode and urldecode functions to store and get non-latin characters in diffrent way. In fact - folder will get weird name (under operating system you will see something like this: %51%%32%%DA%), but you can decode it back into original characters to display them on website.

Here is more information (read best answer):

How do I use filesystem functions in PHP, using UTF-8 strings?

Community
  • 1
  • 1
Kamil
  • 13,363
  • 24
  • 88
  • 183
  • What does URL encoding have to do with the file system? – Álvaro González Nov 13 '12 at 11:22
  • It allows to store characters unsupported in filesystem. You can urldecode($name) when reading and you can display "original" file/folder name. Anyway - from file browser you will see codes like this `%C2%` instead of original symbols. – Kamil Nov 13 '12 at 11:25
  • More precisely - this is a function designed to convert any character to string without national/special characters. Its supposed to encode URL's (pass variables in url etc.), but very often it is used to "normalize" text for any computer system with any locale setup. – Kamil Nov 13 '12 at 11:31
  • 1
    You can also abuse base64_encode for that purpose. `urlencode()` originated for URLs, not for filesystem. It's a nice hack though. – Madara's Ghost Nov 13 '12 at 11:45