Tuesday, January 1, 2013

PHP filter with preg_replace allow only letters and some other characters

Only receive - letters, numbers, spaces
$str = preg_replace("/[^A-Za-z0-9 ]/","",$str);
$str = preg_replace("/[^A-Za-z0-9\s]/","",$str);
$str = preg_replace("/[^A-Za-z0-9[:space:]]/","",$str);
$str = preg_replace("/([^a-z0-9A-Z[:space:]\'\"\?\!\,\.\-\:\~]+)/", "", $str]);
$str = preg_replace("/([--]+)/", "-", $str); 
 
$str = preg_replace("/<\/address>\r\n/e", "'</address>'", $str); 
When using the /e modifier in preg_replace, you have to pass a string of code to 
be evaluated as the replacement parameter, not an already-evaluated expression.
 
$str = preg_replace("/<\/address>[[:space:]]*?<address/e", "'</address><address'", $str); 
 
 
 

No comments:

Post a Comment