<?php 
	function alphaname($nom)
	{
		$len = strlen($nom);
		$nom = strtolower(trim($nom));
		for($i=0;$i<$len;$i++)
		{
			$ord = ord($nom[$i]);
			if(($ord>=65 and $ord<=90) or ($ord>=97 and $ord<=122) or ($ord>=48 and $ord<=57) or $ord=='46')
			{
				
			}
			else $nom[$i] = '_';
		}
		$nom = str_replace(' ','_',$nom);
		$nom = str_replace('__','_',$nom);
		$nom = str_replace('__','_',$nom);
		$nom = str_replace('__','_',$nom);
		$nom = str_replace('_.','.',$nom);
		return ($nom);
	}
	function extension($file)
	{
		$p = strrpos($file,'.');
		if($p<=0) return false;
		$ext = substr($file,$p);
		return  $ext;
	}
	function filenextname($path)
	{
		if(!is_file($path)) return $path;
		//identifier le dernier nombre
		$pos = strrpos($path,'.');
		$k = 1;
		$ext = substr($path,$pos);
		$tem = substr($path,$pos-$k,$k);
		
		while(is_numeric($tem))
		{
			$last = $tem;
			$k++;
			$tem = substr($path,$pos-$k,$k);
			
		}
		$anc = 
		$tem = $last;
		$npath = str_replace($anc.$ext,$tem.$ext,$path);
		while(is_file($npath))
		{
			$tem++;
			$npath = str_replace($anc.$ext,$tem.$ext,$path);
			if($g>500) break;$g++;
		}
		return $npath;
	}
	function iconefile($file,$icopath=ICONE_PATH)
	{
		$ext  = extension(strtolower($file));
		$ico = substr($ext,1,3);
		$fileico = $icopath.$ico.'.png';
		if(is_file($fileico)) return $fileico;
		return false;
	}
	function getfiledata($file)
	{
		if(!is_file($file)) return array();
		$res['name'] = basename($file);
		$res['size'] = filesize($file);
		$res['tmp_name'] = $file;	
		$res['error'] = 0;
		return $res;
	}
	
	function alphanumericname($file)
	{
		$size = strlen($file);
		$val = "";
		for($i=0;$i<$size;$i++)
		{
			$ord = ord($file[$i]);
			if($file[$i]=='/' or ($ord>=65 and $ord<=90) or ($ord>=97 and $ord<=122) or ($ord>=48 and $ord<=57) or $ord==46)
			{
				$val.= $file[$i];
				$last = $file[$i];
			}
			else 
			{
				if($last!=" ")
				{
					$val.= " ";
				}
				$last = " ";
			}
			
		}
		
		return str_replace(' ','_',trim($val));
	}
	function delete_accents($str, $encoding='utf-8')
	{
		// transformer les caractères accentués en entités HTML
		
		$str = mb_encode($str);
		return $str;
		$str = htmlentities($str, ENT_NOQUOTES, $encoding);
		
	 
		// remplacer les entités HTML pour avoir juste le premier caractères non accentués
		// Exemple : "&ecute;" => "e", "&Ecute;" => "E", "Ã " => "a" ...
		$str = preg_replace('#&([A-za-z])(?:acute|grave|cedil|circ|orn|ring|slash|th|tilde|uml);#', '\1', $str);
	 
		// Remplacer les ligatures tel que : Œ, Æ ...
		// Exemple "Å“" => "oe"
		$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
		// Supprimer tout le reste
		$str = preg_replace('#&[^;]+;#', '', $str);
	 
		return $str;
	}
	function rewritename($file)
	{
		
		$file = substr(trim($file),0,70);
		$file = strtolower(stripslashes(delete_accents($file)));
		$file =  str_replace("'",'',trim($file));
		$file =  str_replace("/",'-',trim($file));

		$size = strlen($file);
		$val = "";
		for($i=0;$i<$size;$i++)
		{
			$ord = ord($file[$i]);
			if($file[$i]=='/' or ($ord>=65 and $ord<=90) or ($ord>=97 and $ord<=122) or ($ord>=48 and $ord<=57) or $ord==46)
			{
				$val.= $file[$i];
				$last = $file[$i];
			}
			else 
			{
				if($last!=" ")
				{
					$val.= " ";
				}
				$last = " ";
			}
			
		}
		$val =  str_replace(' ','-',trim($val));
		
		return str_replace(' ','-',trim($val));
	}
?>