«
»
(Français) URLEncode

(Français) URLEncode

Sorry, this entry is only available in French. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

La fonction URLEncode, disponible au moins depuis la version 12, encode les caractères ASCII afin qu’ils soit correctement reconnus dans une URL.

Depuis la version 17, WinDev propose les projets nativement en Unicode. Par contre, la fonction URLEncode ne gère pas l’Unicode. Il faut attendre la version 22 pour cela.

Entre les deux, il faut se taper la conversion à la main.  Alors pour ceux qui utilisent encore des projets inférieurs à 22 et qui auraient besoin de cette conversion, voici un bout de code qui vous évite un travail fastidieux.

PROCEDURE URLEncodeUnicode(sTexte est une chaîne) : chaîne
//la chaîne ne doit pas contenir de caractère ASCII 1
//ref: https://www.w3schools.com/tags/ref_urlencode.ASP
//encodage uniquement les codes qui sont différents de l'ASCII
sRes est une chaîne = Remplace(sTexte,"%","%25")
sRes=Remplace(sRes,"%",Caract(1))	//sera traité à la fin
sRes=Remplace(sRes,"`","%E2%82%AC");sRes=Remplace(sRes,"´","%C2%B4")
sRes=Remplace(sRes,"ƒ","%C6%92")
sRes=Remplace(sRes,"…","%E2%80%A6")
sRes=Remplace(sRes,"†","%E2%80%A0");sRes=Remplace(sRes,"‡","%E2%80%A1")
sRes=Remplace(sRes,"š","%C5%A1");sRes=Remplace(sRes,"Š","%C5%A0")
sRes=Remplace(sRes,"‹","%E2%80%B9");sRes=Remplace(sRes,"›","%E2%80")
sRes=Remplace(sRes,"œ","%C5%93");sRes=Remplace(sRes,"Œ","%C5%92")
sRes=Remplace(sRes,"ž","%C5%BE");sRes=Remplace(sRes,"Ž","%C5%BD")
sRes=Remplace(sRes,"‘","%E2%80%98");sRes=Remplace(sRes,"’","%E2%80%99");sRes=Remplace(sRes,"“","%E2%80%9C");sRes=Remplace(sRes,"”","%E2%80%9D");sRes=Remplace(sRes,"„","%E2%80%9E")
sRes=Remplace(sRes,"•","%E2%80%A2");sRes=Remplace(sRes,"·","%C2%B7");sRes=Remplace(sRes,"°","%C2%B0")
sRes=Remplace(sRes,"–","%E2%80%93");sRes=Remplace(sRes,"—","%E2%80%94")
sRes=Remplace(sRes,"˜ ","%CB%9C");sRes=Remplace(sRes,"ˆ","%CB%86")
sRes=Remplace(sRes,"™","%E2%84")
sRes=Remplace(sRes,"Ÿ","%C5%B8")
sRes=Remplace(sRes,"¡","%C2%A1");sRes=Remplace(sRes,"¿","%C2%BF")
sRes=Remplace(sRes,"¢","%C2%A2")
sRes=Remplace(sRes,"£","%C2%A3")
sRes=Remplace(sRes,"¤","%C2%A4")
sRes=Remplace(sRes,"¥","%C2%A5")
sRes=Remplace(sRes,"¦","%C2%A6")
sRes=Remplace(sRes,"§","%C2%A7");sRes=Remplace(sRes,"¶","%C2%B6")
sRes=Remplace(sRes,"©","%C2%A9");sRes=Remplace(sRes,"®","%C2%AE")
sRes=Remplace(sRes,"ª","%C2%AA")
sRes=Remplace(sRes,"«","%C2%AB");sRes=Remplace(sRes,"»","%C2%BB")
sRes=Remplace(sRes,"¬","%C2%AC")
sRes=Remplace(sRes,"¯","%C2%AF")
sRes=Remplace(sRes,"±","%C2%B1")
sRes=Remplace(sRes,"µ","%C2%B5")
sRes=Remplace(sRes,"¸","%C2%B8")
sRes=Remplace(sRes,"º","%C2%BA");sRes=Remplace(sRes,"¹","%C2%B9");sRes=Remplace(sRes,"²","%C2%B2");sRes=Remplace(sRes,"³","%C2%B3")
sRes=Remplace(sRes,"¼","%C2%BC");sRes=Remplace(sRes,"½","%C2%BD");sRes=Remplace(sRes,"¾","%C2%BE")
sRes=Remplace(sRes,"À","%C3%80");sRes=Remplace(sRes,"Á","%C3%81");sRes=Remplace(sRes,"Â","%C3%82");sRes=Remplace(sRes,"Ã","%C3%83");sRes=Remplace(sRes,"Ä","%C3%84");sRes=Remplace(sRes,"Å","%C3%85")
sRes=Remplace(sRes,"ç","%C3%A7");sRes=Remplace(sRes,"Ç","%C3%87")
sRes=Remplace(sRes,"È","%C3%88");sRes=Remplace(sRes,"È","%C3%89");sRes=Remplace(sRes,"Ê","%C3%8A");sRes=Remplace(sRes,"Ë","%C3%8B")
sRes=Remplace(sRes,"è","%C3%A8");sRes=Remplace(sRes,"é","%C3%A9");sRes=Remplace(sRes,"ê","%C3%AA");sRes=Remplace(sRes,"ë","%C3%AB")
sRes=Remplace(sRes,"Ì","%C3%8C");sRes=Remplace(sRes,"Í","%C3%8D");sRes=Remplace(sRes,"Î","%C3%8E");sRes=Remplace(sRes,"Ï","%C3%8F")
sRes=Remplace(sRes,"ì","%C3%AC");sRes=Remplace(sRes,"í","%C3%AD");sRes=Remplace(sRes,"î","%C3%AE");sRes=Remplace(sRes,"ï","%C3%AF")
sRes=Remplace(sRes,"Ð","%C3%90");sRes=Remplace(sRes,"ð","%C3%B0")
sRes=Remplace(sRes,"Ñ","%C3%91");sRes=Remplace(sRes,"ñ","%C3%B1")
sRes=Remplace(sRes,"Ò","%C3%92");sRes=Remplace(sRes,"Ó","%C3%93");sRes=Remplace(sRes,"Ô","%C3%94");sRes=Remplace(sRes,"Õ","%C3%95");sRes=Remplace(sRes,"Ö","%C3%96")
sRes=Remplace(sRes,"ò","%C3%B2");sRes=Remplace(sRes,"ó","%C3%B3");sRes=Remplace(sRes,"ô","%C3%B4");sRes=Remplace(sRes,"õ","%C3%B5");sRes=Remplace(sRes,"ö","%C3%B6")
sRes=Remplace(sRes,"×","%C3%97")
sRes=Remplace(sRes,"Ø","%C3%98");sRes=Remplace(sRes,"ø","%C3%B8")
sRes=Remplace(sRes,"Ù","%C3%99");sRes=Remplace(sRes,"Ú","%C3%9A");sRes=Remplace(sRes,"Û","%C3%9B");sRes=Remplace(sRes,"Ü","%C3%9C")
sRes=Remplace(sRes,"ù","%C3%B9");sRes=Remplace(sRes,"ú","%C3%BA");sRes=Remplace(sRes,"û","%C3%BB");sRes=Remplace(sRes,"ü","%C3%BC")
sRes=Remplace(sRes,"Ý","%C3%9D");sRes=Remplace(sRes,"ý","%C3%BD");sRes=Remplace(sRes,"ÿ","%C3%BF")
sRes=Remplace(sRes,"Þ","%C3%9E");sRes=Remplace(sRes,"þ","%C3%BE")
sRes=Remplace(sRes,"ß","%C3%9F")
sRes=Remplace(sRes,"æ","%C3%A6");sRes=Remplace(sRes,"Æ","%C3%86")
sRes=Remplace(sRes,"à","%C3%A0");sRes=Remplace(sRes,"á","%C3%A1");sRes=Remplace(sRes,"â","%C3%A2");sRes=Remplace(sRes,"ã","%C3%A3");sRes=Remplace(sRes,"ä","%C3%A4");sRes=Remplace(sRes,"å","%C3%A5")
sRes=Remplace(sRes,"÷","%C3%B7")
sRes=Remplace(sRes,"‰","%E2%80%B0");sRes=Remplace(sRes,"%",Caract(1))
sRes=URLEncode(UnicodeVersAnsi(sRes))
sRes=Remplace(sRes,"%01","%")
RENVOYER sRes