Skip to content

Instantly share code, notes, and snippets.

@gelanivishal
Created March 6, 2017 07:09
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 gelanivishal/60ce566ac90321eb9411c9ea02dbedfc to your computer and use it in GitHub Desktop.
Save gelanivishal/60ce566ac90321eb9411c9ea02dbedfc to your computer and use it in GitHub Desktop.
String sanitizer for filename
public static function normalizeString ($str = '')
{
$str = strip_tags($str);
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
$str = strtolower($str);
$str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
$str = htmlentities($str, ENT_QUOTES, "utf-8");
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
$str = str_replace(' ', '-', $str);
$str = rawurlencode($str);
$str = str_replace('%', '-', $str);
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment