Re: Dealing with spaces and punctuation in uploaded filenames (tjlq)
| From: | Jason Wong | Date: | Sun, 14 Jul 2002 04:24:02 +0000 |
| Subject: | Re: Dealing with spaces and punctuation in uploaded filenames (tjlq) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-107564@lists.php.net to get a copy of this message | ||
On Sunday 14 July 2002 09:20, Tim Luoma wrote:
> and this is what I was trying to use to remove the space and punctuation
> (all one line, might wrap in email):
>
> $SAFEFILENAME = ereg_replace ("[[:punct:]]+[[:blank:]]+", "", $FILENAME);
>
> But that does not seem to be working, and I have not been able to figure
> out why.
What the above seems to be doing is replace:
a series of one or more punctuation marks FOLLOWED BY
a series of one or more spaces
Which is not what you want. Presumably anything which isn't alphanumeric is
classed as either space or punctuation? If so:
I prefer preg_replace so try:
$SAFEFILENAME = preg_replace('/[^a-zA-Z0-9]/', '', $FILENAME);
*** Untested use with caution ***
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
While you don't greatly need the outside world, it's still very
reassuring to know that it's still there.
*/