> I want to remove unwanted characters from filenames of files uploaded to
> our server. I am currently using strtr to do this. I have a few characters
> that are being removed but I would also like a single quote to be removed
> if it is in the filename. I think it has to be escaped in the command
> though. How do I do this?

You shouldn't "remove unwanted characters" you should only allow the
characters you want. There's a difference. You should say that only
alphanumeric characters are allowed and all others should be removed, rather
than saying remove spaces and quotes, for example. The reason being is that
there may be other characters out there that cause problems in your script,
but you don't know about them right now. If you only _allow_ a certain set
of characters, you eliminate everything else so it can't do any harm.

$safe_name = preg_replace('/[^a-zA-Z0-9]/','',$unsafe_name);

That will only allow a-Z and 0-9 characters (alphanumeric) for example.
Everything else will be removed.

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to