Only letting some chars though

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Only letting some chars though

Post by shiznatix »

Hey hey! Ok so I just want to know if this will work. I want to only let A-Z a-z 0-9 . - and _ though. so I think its something like this...

Code: Select all

$filename = preg_replace('#[^A-Za-z0-9\.\-_]#', $filename);
am I missing anything?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Test it at RegExpLib.

EDIT | Corrected incorrect edit.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

missing third argument.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

feyd wrote:missing third argument.

Code: Select all

$replace = '';
$filename = preg_replace('#[^A-Za-z0-9\.\-_]#m', $replace, $filename);
like so? I added the multi-line reader thing but its a filename so can filenames actually contain a line break?
Post Reply