Restrict characters used in a string
        Posted  
        
            by Jeremy Rudd
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jeremy Rudd
        
        
        
        Published on 2010-06-15T14:25:24Z
        Indexed on 
            2010/06/15
            14:42 UTC
        
        
        Read the original article
        Hit count: 219
        
How do I restrict a string to whitelisted characters?
// "HOW am I to understand; this is, BAD"
$str = restrictTo($str,"0-9a-z,. ");
// " am I to understand this is, "
Is there an inbuilt function in PHP that does something close? I can't formulate a regular expression for this though :(
© Stack Overflow or respective owner