Utilizo uma outra função (acho que na época peguei no fórum do iMasters).
public function sem_acento($string)
{
$ac = array('/[ÂÀÁÄÃ]/' => 'A',
'/[âãàáä]/' => 'a',
'/[ÊÈÉË]/' => 'E',
'/[êèéë]/' => 'e',
'/[ÎÍÌÏ]/' => 'I',
'/[îíìï]/' => 'i',
'/[ÔÕÒÓÖ]/' => 'O',
'/[ôõòóö]/' => 'o',
'/[ÛÙÚÜ]/' => 'U',
'/[ûúùü]/' => 'u',
'/ç/' => 'c',
'/Ç/' => 'C');
return preg_replace(array_keys($ac), array_values($ac), $string);
}
A código do Rafael Bomfin tá bem limpo *:)*
2009/11/25 Rafael V. de Oliveira <[email protected]>
> Eu extendi o url_title para o arquivo MY_url_helper.php e deixei-lo desta
> forma:
>
> if (! function_exists('url_title'))
>
> {
>
> /**
>
> * Create URL Title
>
> *
>
> * Takes a "title" string as input and creates a
>
> * human-friendly URL string with either a dash
>
> * or an underscore as the word separator.
>
> *
>
> * @access public
>
> * @param string the string
>
> * @param string the separator: dash, or underscore
>
> * @return string
>
> */
>
> function url_title($str, $separator = 'underscore')
>
> {
>
> if ($separator == 'dash')
>
> {
>
> $search = '_';
>
> $replace = '-';
>
> }
>
> else
>
> {
>
> $search = '-';
>
> $replace = '_';
>
> }
>
>
>
> $str = convert_accented_characters($str);
>
>
>
> $trans = array(
>
> $search => $replace,
>
> "\s+" => $replace,
>
> "[^a-z0-9".$replace."]" => '',
>
> $replace."+" => $replace,
>
> $replace."$" => '',
>
> "^".$replace => ''
>
> );
>
>
>
> $str = strip_tags(strtolower($str));
>
>
>
> foreach ($trans as $key => $val)
>
> {
>
> $str = preg_replace("#".$key."#", $val, $str);
>
> }
>
>
>
> return trim(stripslashes($str));
>
> }
>
> }
>
> function convert_accented_characters($var, $enc = 'UTF-8')
>
> {
>
>
>
> $acentos = array(
>
> 'A' =>
> '/À|Á|Â|Ã|Ä|Å/',
>
> 'a' =>
> '/à|á|â|ã|ä|å/',
>
> 'C' => '/Ç/',
>
> 'c' => '/ç/',
>
> 'E' =>
> '/È|É|Ê|Ë/',
>
> 'e' =>
> '/è|é|ê|ë/',
>
> 'I' =>
> '/Ì|Í|Î|Ï/',
>
> 'i' =>
> '/ì|í|î|ï/',
>
> 'N' => '/Ñ/',
>
> 'n' => '/ñ/',
>
> 'O' =>
> '/Ò|Ó|Ô|Õ|Ö/',
>
> 'o' =>
> '/ò|ó|ô|õ|ö/',
>
> 'U' =>
> '/Ù|Ú|Û|Ü/',
>
> 'u' =>
> '/ù|ú|û|ü/',
>
> 'Y' => '/Ý/',
>
> 'y' => '/ý|ÿ/',
>
> 'a.' => '/ª/',
>
> 'o.' => '/º/'
>
> );
>
>
>
> $var = preg_replace($acentos,
>
>
> array_keys($acentos),
>
>
> htmlentities($var, ENT_NOQUOTES, $enc));
>
> return strtolower($var);
>
> }
>
>
>
> Desta forma, continuo a chamar o url_title normalmente
>
> echo url_title(.....);
>
>
>
> *De:* [email protected] [mailto:
> [email protected]] *Em nome de *jonatan froes
> *Enviada em:* quarta-feira, 25 de novembro de 2009 14:27
> *Para:* [email protected]
> *Assunto:* [CodeIgniter] Estendendo o helper url_title()
>
>
>
> Boa tarde, pessoal.
>
> Meu problema é mais com ER que com CI. Mas vamos lá.
>
> A função url_title do CI "come" as letras com acento. Eu preciso que ela
> apenas tire os acentos.
>
> Por exemplo, se eu usar url_title('CI é mão na roda') vou ter
> "CI-mo-na-roda". Preciso que a função me retorne "CI-e-mao-na-roda". Alguém
> já fez isso aí e pode me ajudar.
>
> Valew
> Jônatan Fróes
> ---------------------------------------------
> http://twitter.com/jonatanfroes
> http://tinyurl.com/jonatanfroes
> http://www.webtrindade.com.br
> http://www.projetoacolher.com.br
>
>
> ------------------------------
>
> Veja quais são os assuntos do momento no Yahoo! + Buscados: Top
> 10<http://br.rd.yahoo.com/mail/taglines/mail/*http:/br.maisbuscados.yahoo.com/>-
> Celebridades<http://br.rd.yahoo.com/mail/taglines/mail/*http:/br.maisbuscados.yahoo.com/celebridades/>-
> Música<http://br.rd.yahoo.com/mail/taglines/mail/*http:/br.maisbuscados.yahoo.com/m%C3%BAsica/>-
> Esportes<http://br.rd.yahoo.com/mail/taglines/mail/*http:/br.maisbuscados.yahoo.com/esportes/>
>
> _______________________________________________
> Lista mailing list
> [email protected]
> http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br
>
>
--
Att,
Vinicius Cruz
http://twitter.com/vinaocruz
http://www.viniciuscruz.com/
_______________________________________________
Lista mailing list
[email protected]
http://codeigniter.com.br/mailman/listinfo/lista_codeigniter.com.br