|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Starguezer Smarty n00b
Joined: 12 Jul 2007 Posts: 3
|
Posted: Thu Jul 12, 2007 11:29 am Post subject: Remplacer des lettres avec accent par des lettres sans accen |
|
|
Bonjour,
Depuis quelques jours je cherche desesperement de trouver comment transformer une chaine de charactères contenant des accents par une chaine n'en contenant pas afin de faire de l'URL rewriting.
J'ai bien une solution qui consiste à faire ca mais je me vois mal rajouter bout à bout une batterie de |replace pour chaque caractère accentué :s
$string|replace:"é":"e"
Donc est-ce que quelq'un aurait une solution pour moi ?
Merci de votre aide |
|
Back to top |
|
reb Smarty Rookie
Joined: 17 Aug 2005 Posts: 23
|
Posted: Sun Jul 29, 2007 5:05 pm Post subject: |
|
|
c'est plutôt du ressort de PH que Smarty, mais bon :
Code: |
/**
* Convertit une chaîne avec caractères accentués en chaine ASCII
*/
function unaccent($text) {
$trans = get_html_translation_table(HTML_ENTITIES); // Table des entités dans un tableau
foreach ($trans as $litteral => $entity) { // 2 tableaux : un pour les caractères
//accentués et un pour les autres
if (ord($litteral) >= 192) { // On ignore les autres
//caractères bizarres
//(fractions, quotes etc)
$replace[] = substr($entity, 1, 1); // Récupère le 'E' de '&Eaccute' etc.
$search[] = $litteral; // Récupère la forme accentuée
}
}
return str_replace($search, $replace, $text);
}
|
Last edited by reb on Wed May 05, 2010 10:34 pm; edited 1 time in total |
|
Back to top |
|
Starguezer Smarty n00b
Joined: 12 Jul 2007 Posts: 3
|
Posted: Mon Jul 30, 2007 10:18 am Post subject: |
|
|
Nikel merci beaucoup |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|