Re: recognizing spaces

From: Date: Fri, 16 May 2003 15:16:45 +0000
Subject: Re: recognizing spaces
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-147905@lists.php.net to get a copy of this message
> I am programming folder directory, and have an iput form where users can > name and then create a directory. > (At present this is on my windows machine at home) > > I have created functions that creates an array of all folders in the current > directory, and then if you go into a folder, creates an array of files in > the folder. you you can view or delete the files. > > When creating a folder, if the user inputs a name with a space in it - ie > "New Folder", then it creates, the folder and reads its contents > successfully. > > However when I try to delete (using unlink) then I get a meaasge sying that > the fike doesnt not exist and recognizes the name "New" as opposed to "New > Folder". > > So what I need to do is either recognize the space in the name, make the > adjustment to allow files to be deleted, or I need to prevent users using a > name with a space. > > How would I recognize this space? I'd just convert spaces to an underscore. Or use a regex to matching anything not alphanumeric in the name and reject it if necessary. $safe_name = str_replace(' ','_',$name); or if(preg_match('/[^0-9a-z_-]/i',$name)) { echo 'bad name'; } else { echo 'good name'; } There may be a bug in the unlink function if you can't delete files with a space. You can do it from the command line if you place the name within quotes. Check out the PHP Bugs page to see if there's anyone reporting/working on this... ---John Holmes...

« previous php.general (#147905) next »