need help with regular expression in php

unsped

Platinum Member
Mar 18, 2000
2,323
0
0
im wanting a eregi_replace call that would take a string and strip all characters that are not aA-zZ or the space character. this would strip out line returns 's "s etc.. etc..

any ideas?
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Note that preg_replace() is often faster than ereg_replace().

This one should work, too:

$clean_text = preg_replace ("/([^a-z]|\s)/i", '', $input_text);

note that the small "i" at the end of the pattern indicates that you want the pattern to be case-insensitive.

Also \s means any spaces, including white space, tabs, and new lines. If you want to remove white space only, replace \s with a single space.