Comment transformer les accents dans les urls

smookdogg29

WRInaute discret
Bonjour tout le monde, j'ai un problème au niveau des Urls, je souhaite transformer tous les liens qui contient des accents é à è par e a e
Voilà la structure de mes liens
monsite.com/index.php?post/2012/10/15/T%C3%A9l%C3%A9charger-des-Wallpaper-HD
Ce que je cherche à faire c'est transformer mes url de façon permanente vers
monsite.com/index.php?post/2012/10/15/telecharger-des-wallpaper-hd
(Éviter les accents et transformer les majuscules en minuscule)

merci bcp
 

smookdogg29

WRInaute discret
merci pour le liens donc la fonction est
PHP:
<span class="syntaxdefault">    function slug</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$slug</span><span class="syntaxkeyword">){<br /></span><span class="syntaxdefault">       $bad </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> array</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'Š'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ž'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'‘'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ž'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ÿ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'À'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Á'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Â'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ã'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ä'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Å'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ç'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'È'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'É'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ê'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ë'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ì'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Í'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Î'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ï'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ñ'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'Ò'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ó'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ô'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Õ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ö'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ø'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ù'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ú'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Û'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ü'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ý'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'à'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'á'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'â'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ã'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ä'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'å'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ç'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'è'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'é'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ê'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'ë'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ì'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'í'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'î'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ï'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ñ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ò'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ó'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ô'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'õ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ö'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ø'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ù'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ú'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'û'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ü'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ý'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ÿ'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'Þ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'þ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Ð'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ð'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ß'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Œ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'œ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Æ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'æ'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'µ'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'”'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"'"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'“'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'"'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"\n"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">"\r"</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'_'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'&'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">':'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'/'</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       $good </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> array</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxstring">'S'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Z'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'s'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'z'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Y'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'A'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'C'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'E'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'E'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'E'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'E'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'I'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'I'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'I'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'I'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'N'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'O'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'U'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'U'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'U'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'U'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'Y'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'a'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'c'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'e'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'e'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'e'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'e'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'i'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'i'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'i'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'i'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'n'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'o'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'u'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'u'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'u'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'u'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'y'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'y'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">'TH'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'th'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'DH'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'dh'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ss'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'OE'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'oe'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'AE'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'ae'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'u'</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault">       </span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'-'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'-'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       </span><span class="syntaxcomment">// replace strange characters with alphanumeric equivalents<br /></span><span class="syntaxdefault">       $slug </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> str_replace</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $bad</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $good</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $slug </span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       $slug </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> trim</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$slug</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       </span><span class="syntaxcomment">// remove any duplicate whitespace, and ensure all characters are alphanumeric<br /></span><span class="syntaxdefault">       $bad_reg </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> array</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'/\s+/'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">'/[^A-Za-z0-9\-]/'</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       $good_reg </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> array</span><span class="syntaxkeyword">(</span><span class="syntaxstring">'-'</span><span class="syntaxkeyword">,</span><span class="syntaxstring">''</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       $slug </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> preg_replace</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$bad_reg</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $good_reg</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> $slug</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       </span><span class="syntaxcomment">// and lowercase<br /></span><span class="syntaxdefault">       $slug </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> strtolower</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$slug</span><span class="syntaxkeyword">);<br /></span><span class="syntaxdefault">       <br />       return $slug</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault">    </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span>
Je le mets ou exactement ? Es-que je mets le code directement dans le fichier home (html)
Code:
 {{tpl:include src="_head.html"}}
ou bien dans index.php car j’utilise le système des appels de Template
merci
 

UsagiYojimbo

WRInaute accro
Si tu as des fichiers d'inclusion de fonction, c'est à ce niveau qu'il faut mettre la fonction. Et il faut l'appeler à chaque fois que tu génères un lien.
 

smookdogg29

WRInaute discret
C’est pour Dotclear 2.4 et le système des fonctions des url est un peu flou si vous avez des idées je suis preneur c'est pour éviter ce genre de galère que je préfère utiliser un htaccess
 

Blount

WRInaute impliqué
Si tu as iconv de disponible, il est justement fait pour convertir une chaîne de caractères d'un charset vers un autre.
En passant de l'UTF-8 (ou ISO) vers ASCII, tous les caractères spéciaux (é, à, ô, etc.) seront convertis dans leur équivalent de la table ASCII (e, a, o, etc.).
Mais ça va un peu plus loin, par exemple, le caractère € sera converti en EUR et non pas en "e". Le ® en "(r)", le © en "(c)", etc. Ce que les fonctions maisons ne font pas.

Regarde mon article à ce propos : enlever les accents d’une chaîne de caractères.
Et iconv dans la doc PHP: http://fr.php.net/iconv
 

Discussions similaires

Haut