PHP: Easy way to strip unwanted characters off a string

$output = preg_replace('/[^\da-z A-Z]/', '', $input);

This will remove any characters other than:

  • \d (Numbers)
  • a-z (Lower case characters)
  • A-Z (Upper case characters)
  • And spaces (There is a space between "z" and "A")
 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog