Forum Moderators: coopster

Message Too Old, No Replies

Replace all characters in String except keyboard characters

         

rabbit_fufu

9:02 am on Mar 21, 2004 (gmt 0)

10+ Year Member



Hi all,

I've been trying to figure this one out for a few hours and I'm not making much headway. Hoping someone here knows the quick solution...

I'd like to replace all characters in a string except for the set of keyboard characters. I figure this can probably be done with a preg_replace and some regex, but I'm afraid I need to bone up on my regex some...

If anyone here has any suggestions they'd be greatly appreciated.

Thanks!

Hanu

10:50 am on Mar 21, 2004 (gmt 0)

10+ Year Member



Examples?

dcrombie

12:27 pm on Mar 21, 2004 (gmt 0)



If you use ereg_replace then you can use POSIX character groupings such as

[:alpha:], [:alnum:], [:print:], [:space:], etc.

So what you're looking for might be something like:

$text = eregi_replace ("[^[:print:]]", "", $text);

ergophobe

4:58 pm on Mar 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Keyboard characters? Doesn't that depend on your keyboard?

rabbit_fufu

5:01 pm on Mar 21, 2004 (gmt 0)

10+ Year Member



hey thanks!

rabbit_fufu

5:23 pm on Mar 21, 2004 (gmt 0)

10+ Year Member



> Keyboard characters? Doesn't that
> depend on your keyboard?

Sorry, I guess I wasn't clear enough. I mean low ascii, as in 0-127.

Anyhow, I didn't know about the ^ operator in regex so it all works great now. Thanks guys!