David T-G wrote:

Hi, all --

I would like to make things easier for my users and replace all of the
garbage characters

`'";:[EMAIL PROTECTED]&*()[]{}<>/?\|+=

plus white space (\s) with underscores in the input.  I am, however,
having trouble getting my regexp to work.

I can comfortably do

$i = preg_replace("/[\s]/","_",$i) ;

but trying to add other chars doesn't do a thing.

I want to end up with

A-Za-z0-9_-

(letters, numbers, underscore and dash).

If there isn't a handy character class waiting for me, what must I do to
get those chars replaced?


TIA & HAND


:-D

$i = preg_replace('/[^A-Za-z0-9_-]/', '_', $i);


That means anything that is not in that class should be replaced with '_'.

--
paperCrane <Justin Patrin>

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



Reply via email to