Forum Moderators: coopster

Message Too Old, No Replies

Safe filenames from a form

         

Radiance

9:05 am on Mar 13, 2005 (gmt 0)

10+ Year Member



Making a forum.
So I have a form that will have a "title" field.
I should have this:

Say the title is, $ZJC~@@~$_)( Sj NZ(* )($*I/k/k?hah
It should be stored as,
-sj-NZ-kkhah

with the spcial characters stripped, and spaces replaced with "-". How can I do this without listing all the characters? thanks.

coopster

12:29 pm on Mar 13, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Radiance.

Have you had a look at Regular Expression Functions (Perl-Compatible) [php.net] yet?

Radiance

4:06 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



I do know RegEx, but it would take hours to strip *every* character like that...

stuartc1

4:39 pm on Mar 14, 2005 (gmt 0)

10+ Year Member



Hi,

The simple solution is not to strip all those characters manually, but to suply a list of allowed characters!

an example could be:

$result = eregi_replace([a-z0-9\-\_], "", $string);

Which would only allow a-z (the whole alphabet), 0-9, - and _.

Hope this helps!

Radiance

4:55 pm on Mar 18, 2005 (gmt 0)

10+ Year Member



Would have been if I hadn't deleted the files :P thanks anyway