On Wed, 10 Jul 2002 13:14:44 +0100, you wrote: >I've got an application that requires dos folder names (8.3 standard) as >input. > >I also have PHP, which quite happily can cope with both. > >Can someone help me write a function to translate full paths to dos paths > >Thanks
Maybe this can get you started. I don't have access to a PHP parser right now so this is completely off the top of my head, but maybe it will help a bit. The function below assumes that the path contains backslashes (not forward slashes). It also does not verify that the path is legal in the first place (i.e. that it doesn't contain illegal characters). Additionally, it doesn't deal with filenames, just directory names. Maybe you can extend to handle filenames. :) One last thing. You can't really create a function like this without accessing the filesystem that these files are going to be stored on. For example, let's say you have a file called "my resume.doc" The DOS equivalent to this would be "myresu~1.doc" UNLESS there was already another file in the same directory that had that DOS name. So, let's say there was already another file by the name of "my results.doc" in the directory. Then your "my resume.doc" would be called "myresu~2.doc" The function below does not account for this. Come to think of it, maybe this isn't all that helpful. :-P function fullpath2dospath ($fullpath) { if(preg_match("/^([A-Za-z]:)(.*)$/",$fullpath)) { $driveletter = $matches[1]; $fullpath = $matches[2]; } $dirs = explode("\",$fullpath); foreach($dirs as $index => $dir) { /* Directory only needs to be modified if it contains spaces or is longer than 8 characters */ if(strlen($dir) > 8 || strpos($dir," ")) { $dir = strtr($dir," ",""); $dir = substr($dir,0,6); $dirs[$index] = $dir."~1"; } } $dospath = $driveletter.implode("\",$dirs); return $dospath; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php