<?php
function remove_acentos($string) 
{ 
  return strtolower( str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string)); 
} 

function remove_acentos_teste1($input){
	$enc=mb_detect_encoding($input, 'ISO-8859-1, windows-1251, UTF-8', "true");
	$output = iconv($enc, 'US-ASCII//TRANSLIT', $input);
	print $input . "->" . $output;
}

function remove_acentos_actual($input){
	$old=array('á','à','ã','â','ä',  'é','è','ê','ë', 'í','ì','ï',  'ó','ò','õ','ô','ö',  'ú','ù','û','ü', 'ç','ñ','æ', '&');
	$new=array('a','a','a','a','a',  'e','e','e','e', 'i','i','i',  'o','o','o','o','o',  'u','u','u','u', 'c','n','a', 'e');
	
	
	//$inputl=utf8_decode($input);
	//$inputl=iconv("UTF-8", "ISO-8859-1", $input);
	
	return str_replace($old, $new, (mb_strtolower(utf8_decode($input))));

}

function remove_acentos_teste($input){
	$old=array('á','à','ã','â','ä',  'é','è','ê','ë', 'í','ì','ï',  'ó','ò','õ','ô','ö',  'ú','ù','û','ü', 'ç','ñ','æ', '&');
	$new=array('a','a','a','a','a',  'e','e','e','e', 'i','i','i',  'o','o','o','o','o',  'u','u','u','u', 'c','n','a', 'e');

	if (mb_detect_encoding($input, 'ISO-8859-1, windows-1251, UTF-8', "true")=='UTF-8'){
		print $input . mb_detect_encoding($input, 'ISO-8859-1, windows-1251, UTF-8', "true") . "<br>";
		//$input = mb_convert_encoding($input, 'UTF-8', 'ISO-8859-1');
		$input =mb_strtolower($input);
		$input=utf8_decode($input);
		
		print $input . mb_detect_encoding($input, 'ISO-8859-1, windows-1251, UTF-8', "true") . "<br>";
	} else {
		$input=strtolower($input);
	}
			
		$input=utf8_decode($input);
		$input =strtolower($input);
	return str_replace($old, $new, $input);
}


function generate_seo_titulo($input,$replace = '-')  { 
	 $return=remove_acentos($input);
     $return = @trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
     return str_replace(' ',$replace,$return);  
} 

function generate_seo_link($input, $idCat, $data="", $replace = '-')  {       
	$c= new categoria;
	$path=$c->seo_path($idCat);
	print $path;
	$return=remove_acentos($path);
	print $return; 
    
	$return = str_replace(' ',$replace,$return);
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return substr($data . $return  . $ultimo, 1); 
} 

function generate_seo_link_cat($cat="categoria", $input, $idCat, $data="", $replace = '-')  {       
	$c= new categoria;
	$return=remove_acentos($c->seo_path($idCat, $cat));
	//$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
    
	$return = str_replace(' ',$replace,$return);
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return substr($data . $return  . $ultimo, 1); 
} 

function seo_path($idCat){}

function generate_seo_link_old($input, $idCat, $data="", $replace = '-')  {       
	
	$c= new categoria;
	$return=remove_acentos($c->path($idCat));
	//$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
    $return = str_replace(' ','',$return);  
	
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return $data . $return  . $ultimo; 
} 
?>