Re: reg exp to filter bad characters in filename

by "Richard Walker" <richardwalker(at)onebox.com>

 Date:  Wed, 5 Jun 2002 15:32:37 -0400
 To:  <hwg-languages(at)hwg.org>
 References:  onebox yerpso
  todo: View Thread, Original
Well done, thank you.  I wasn't sure about the use of the ^ with
multiple tokens in the [brackets], I guess it distributes to each
token within the brackets.

Actually though, rather than do automated cleanup of bad
characters I was going to bonk the user on the head with an error
message so they'd be encouraged to rename their files.

Would

if (preg_match ('/[^a-zA-Z_.]/',$filename)) {
    print "BONK!  Rename that poorly named file then try again!";
}

work as well?



----- Original Message -----
From: "Hank Marquardt" <hmarq(at)yerpso.net>
To: "Richard Walker" <richardwalker(at)onebox.com>
Cc: <hwg-languages(at)hwg.org>
Sent: Wednesday, June 05, 2002 1:25 PM
Subject: Re: reg exp to filter bad characters in filename


> $sanitized = preg_replace('/[^a-zA-Z_]/','',$filename);
>
> I didn't test it, but that should work.
>
> On Wed, Jun 05, 2002 at 10:35:25AM -0400, Richard Walker wrote:
> > Yo
> >
> > I wrote a PHP app to allow people to upload files.
Immediately the client
> > proceeds to upload files with all kinds of gunk in them, such
as '+'
> > and ' '.
> >
> > I need a reg exp to filter out everything but alphanumeric,
., and _
> > characters.  I could do a nested if statement or something
but I know
> > there's a nice terse Perl compatible solution.
> >
> > Thanks!
> >
> > --
> > Richard Walker
> > RichardWalker(at)onebox.com - email
> >
> >
>
> --
> Hank Marquardt <hank(at)yerpso.net>
> http://web.yerpso.net
> GPG Id: 2BB5E60C
> Fingerprint: D807 61BC FD18 370A AC1D  3EDF 2BF9 8A2D 2BB5 E60C
> *** Web Development: PHP, MySQL/PgSQL - Network Admin:
Debian/FreeBSD
> *** PHP Instructor - Intnl. Webmasters Assn./HTML Writers Guild
> *** Beginning PHP && PHP II -- Starting March 25, 2002
> *** See http://www.hwg.org/services/classes
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.368 / Virus Database: 204 - Release Date: 6/2/2002

HWG: hwg-languages mailing list archives, maintained by Webmasters @ IWA