Created
March 6, 2017 07:09
-
-
Save gelanivishal/60ce566ac90321eb9411c9ea02dbedfc to your computer and use it in GitHub Desktop.
String sanitizer for filename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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