Skip to content

Instantly share code, notes, and snippets.

@Stichoza
Created October 25, 2012 13:47
Show Gist options
  • Save Stichoza/3952636 to your computer and use it in GitHub Desktop.
Save Stichoza/3952636 to your computer and use it in GitHub Desktop.
A simple PHP function to strip strings and numbers.
<?php
function strip_string($str, $case) {
switch ($case) {
case "az": return preg_replace("/[^a-zA-Z]+/", "", $str);
case "num": return preg_replace("/[^0-9]+/", "", $str);
case "num+az": default: return preg_replace("/[^a-zA-Z0-9]+/", "", $str);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment