Skip to content

Instantly share code, notes, and snippets.

@thinkerytim
Created November 21, 2009 01:15
Show Gist options
  • Save thinkerytim/239936 to your computer and use it in GitHub Desktop.
Save thinkerytim/239936 to your computer and use it in GitHub Desktop.
<?php
function filename_safe($filename) {
$temp = $filename;
$temp = strtolower($temp);
$temp = str_replace(" ", "_", $temp);
// Loop through string
$result = '';
for ($i=0; $i<strlen($temp); $i++) {
if (preg_match('([0-9]|[a-z]|_)', $temp[$i])) {
$result = $result . $temp[$i];
}
}
return $result;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment