Skip to content

Instantly share code, notes, and snippets.

@kanonji
Created April 7, 2011 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanonji/908595 to your computer and use it in GitHub Desktop.
Save kanonji/908595 to your computer and use it in GitHub Desktop.
Remove ASCII unavailable for filename
<?php
/**
* \x00-\x1f\x7f: Controll Characters
* \x22 "
* \x2a *
* \x2f /
* \x3a :
* \x3c <
* \x3e >
* \x3f ?
* \x5c \
* \x7c |
*/
function removeOfWindows( $str ){
return preg_replace('/[\x00-\x1f\x7f\x22\x2a\x2f\x3a\x3c\x3e\x3f\x5c\x7c]/', '', $str );
}
function removeOfMac( $str ){
return preg_replace('/[\x00-\x1f\x7f\x3a]/', '', $str );
}
function removeOfLinux( $str ){
return preg_replace('/[\x00-\x1f\x7f\x2f]/', '', $str );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment