Example #1
0
 public static function url($string)
 {
     $url = mb_strtolower($string);
     $url = \Ip\Internal\Text\Transliteration::transform($url);
     $replace = array(" " => "-", "/" => "-", "\\" => "-", "\"" => "-", "\\'" => "-", "„" => "-", "“" => "-", "&" => "-", "%" => "-", "`" => "-", "!" => "-", "@" => "-", "#" => "-", "\$" => "-", "^" => "-", "*" => "-", "(" => "-", ")" => "-", "{" => "-", "}" => "-", "[" => "-", "]" => "-", "|" => "-", "~" => "-", "." => "-", "+" => "-", "'" => "-", "?" => "-", ":" => "-", ";" => "-");
     $url = strtr($url, $replace);
     $url = preg_replace('/-+/', '-', $url);
     return $url;
 }
Example #2
0
 /**
  * @param $fileName
  * @internal param string $file File name.
  * @return string New (or the same) file without special characters.
  */
 public static function cleanupFileName($fileName)
 {
     $fileName = \Ip\Internal\Text\Transliteration::transform($fileName);
     $fileName = utf8_decode($fileName);
     $spec = array("'", "%", "?", "-", "+", " ", "<", ">", "(", ")", "/", "\\", "&", ",", "!", ":", "\"", "?", "|");
     $fileName = str_replace($spec, '_', $fileName);
     $fileName = preg_replace('/[^\\w\\._]+/', '_', $fileName);
     // It overlaps with above replace file. But for historical reasons let it be.
     $fileName = preg_replace('/_+/', '_', $fileName);
     //leave only the last dot in filenames. Files with double extensions might be executed on most of the servers. Eg. hack.php.jpgx
     $pathParts = pathinfo($fileName);
     $fileName = str_replace('.', '_', $pathParts['filename']);
     if (!empty($pathParts['extension'])) {
         $fileName .= '.' . $pathParts['extension'];
     }
     if ($fileName == '') {
         $fileName = 'file';
     }
     return $fileName;
 }