All pastes #994493 Raw Edit

Miscellany

public text v1 · immutable
#994493 ·published 2008-04-23 13:23 UTC
rendered paste body
// wrapped by a 'function_exists', since it might already be defined..
if (!function_exists('safe_filename')) {

	/**
	 * Bepaalt de 'safe_string' die gebruikt kan worden voor bestandsnamen
	 *
	 * @param string $str
	 * @return string de file's extensie of lege string
	 *
	 */
	function safe_filename($str) {

		$str = strip_tags($str);

		$str = str_replace("&", "", $str);
    
		$str = strtr($str, "\xA1\xAA\xBA\xBF\xC0\xC1\xC2\xC3\xC5\xC7\xC8\xC9\xCA\xCB\xCC\xCD".
        "\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD8\xD9\xDA\xDB\xDD\xE0\xE1\xE2\xE3\xE5\xE7\xE8".
        "\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF8\xF9\xFA\xFB\xFD\xFF",
        "!ao?AAAAACEEEEIIIIDNOOOOOUUUYaaaaaceeeeiiiidnooooouuuyy");

		$str = strtr($str, array("\xC4"=>"Ae", "\xC6"=>"AE", "\xD6"=>"Oe", "\xDC"=>"Ue", "\xDE"=>"TH",
        "\xDF"=>"ss", "\xE4"=>"ae", "\xE6"=>"ae", "\xF6"=>"oe", "\xFC"=>"ue", "\xFE"=>"th"));


		$str=str_replace(" ", "_", $str);
    
		$str=strtolower(preg_replace("/[^a-zA-Z0-9_\-\.]/", "", $str));
		
		$str=str_replace("__", "_", $str);
		$str=str_replace("__", "_", $str);

		return $str;
	}
}