Skip to content

Instantly share code, notes, and snippets.

@jeremyboggs
Created May 24, 2012 03:50
Show Gist options
  • Save jeremyboggs/2779332 to your computer and use it in GitHub Desktop.
Save jeremyboggs/2779332 to your computer and use it in GitHub Desktop.
<?php
function sanitize_string($string) {
$string = strtolower($string);
// Gets rid of spaces
$sanitized = preg_replace('/\s/', '', $string);
// Gets rid of non-alphanumerics
$sanitized = preg_replace( '/[^A-Za-z0-9_]/', '', $string );
return $sanitized;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment