Forum Moderators: coopster

Message Too Old, No Replies

I just want alphanumeric characters from a given string

strip all metacharacters

         

Ook_Ook

6:28 am on Oct 1, 2003 (gmt 0)

10+ Year Member



I was hoping someone could offer some advice on how I can take a string, and only extract from that string alphanumeric charachters. In addition, I would also like to replace any spaces with a "-" and convert the whole thing to lowercase.

I know I can use str_replace to do most the work, but then I have to make sure I name every potential charachter, which seems excessive.

Any suggestions?

gethan

2:10 pm on Oct 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use preg_replace - based on the perl regular expression code.

You would use something like:

$string = preg_replace("/\W/","-",$string);

which would replace all NON alphanumeric characters with a -

You can build arrays with all the various complex rules you'd like in them. Good luck.

See: [hu.php.net...]