Page 1 of 1

build url web for a file name with accented letter

Posted: Sat Jul 04, 2015 8:46 pm
by jmburnod
Hi All
I look for build a valid url for a file name with accented letters
On a server there is a file called "boîte.png", I noticed the http name is "bo%C3%AEte.png" and it works with this name

I thought I could use urlencode to get the same but
urlEncode(boîte) = "bo%94te"

How can I translate "boîte.png" to "bo%C3%AEte.png" ?
Thanks again for your lights
Jean-Marc

Re: how build url web for a file name with accented letter ?

Posted: Sat Jul 04, 2015 10:54 pm
by zaxos
Replace î with %C3% or the reverse? I`m guessing this char is allways represented like that.

Code: Select all

Put "http:\\blablabla\blabla\boîte.jpg" into tUrl
Replace "î" with "%C3%" in tUrl
Just a thought

Re: how build url web for a file name with accented letter ?

Posted: Sun Jul 05, 2015 11:11 am
by jmburnod
Hi Zaxos
Thanks for reply
Replace î with %C3% or the reverse?
Unfortunately not
With your script I get "bo%C3%te.jpg" instead "bo%C3%AEte.jpg"
Best regards
Jean-Marc

Re: how build url web for a file name with accented letter ?

Posted: Sun Jul 05, 2015 11:19 am
by SparkOut
then just
replace "î" with "%C3%AE" in tUrl

but it might be worthwhile trying to find our why the filename has been encoded like that. It looks like a problem interpreting between UTF-8 and ISO-8859-1 or Windows-1252 code sets. If you can find out the encoding used, you might be able to make it match from LiveCode by using the matching code set, rather than hard coding a replacement. But that might get pretty complicated.

Re: how build url web for a file name with accented letter ?

Posted: Sun Jul 05, 2015 8:02 pm
by jacque
If you are using LC 7.x you can use the built-in unicode support to translate:

Code: Select all

get "boîte" -- or any other text
put urlEncode(textEncode(it,"utf8"))
In LC 7, all text exported or imported from/to LiveCode should be textEncoded or textDecoded so it is compatible with external apps and servers that have unicode support. Text encoding will not alter non-unicode characters, so it is safe to use on all text.

If you are using LC 6.x then you'll need to use the more awkward uniEncode/uniDecode functions which are now deprecated.

Re: how build url web for a file name with accented letter ?

Posted: Sun Jul 05, 2015 8:25 pm
by SparkOut
Ah great, now I can test I see that is the unicode representation in UTF-8. I was unsure if the file name had been encoded with a different (eg Windows-1252) encoding. This works nicely though. Here's your solution Jean-Marc.

Re: how build url web for a file name with accented letter ?

Posted: Sun Jul 05, 2015 10:41 pm
by jmburnod
Thanks at all,
It works fine with LC 7.
Jaque said there is a way for LC 6.7 but I'm not yet able to use it
Is there an example of "uniEncode/uniDecode" way for 6.7 ?
Jean-Marc

Re: how build url web for a file name with accented letter ?

Posted: Mon Jul 06, 2015 9:07 am
by jmburnod
I found a quick but dirty way to translate an accented file name.
We can create a list of translated accented chars in LC 7 using unicode.
This list can be used in LC 6.7 with a search/replace

Re: how build url web for a file name with accented letter ?

Posted: Mon Jul 06, 2015 6:07 pm
by jacque
You can use the older method this way:

Code: Select all

get "boîte"
  put urlEncode(unidecode(uniencode(it), "UTF8")) into tURL

Re: how build url web for a file name with accented letter ?

Posted: Mon Jul 06, 2015 9:42 pm
by jmburnod
Thanks a lot Jacque
That is the way for LC 6.7

Re: build url web for a file name with accented letter solved

Posted: Tue Jul 03, 2018 6:25 pm
by jmburnod
Hi All,
It seems something changed about this.
url file name on server for "zéro_2.png" = "ze%CC%81ro_2.png"

I tried this

Code: Select all

  get "zéro_2.png"
  put urlEncode(unidecode(uniencode(it), "UTF8")) 
return "z%C3%A9ro_2.png" instead "ze%CC%81ro_2.png"
Thanks in advance for your help
Jean-Marc

Re: build url web for a file name with accented letter

Posted: Wed Jul 04, 2018 6:12 pm
by jacque
Maybe you have to go back to textEncode?

Re: build url web for a file name with accented letter

Posted: Thu Jul 05, 2018 6:13 pm
by jmburnod
Thanks again Jacqueline
We have tested on a ownCloud and it works with this:

Code: Select all

   get "zéro_2.png"
   put textencode(it,"UTF-8") into tTE
   put urlEncode(tTE) into tUrltTE
   replace "+" with "%20" in tUrltTE
No idea why our site does different encoding

P.S: my hight score on Klondike is 840. What is the max score ? 8)

Re: build url web for a file name with accented letter

Posted: Thu Jul 05, 2018 6:25 pm
by jacque
my hight score on Klondike is 840. What is the max score ?
LOL. I can't remember but I think you're close. :)

Re: build url web for a file name with accented letter

Posted: Thu Jul 05, 2018 8:08 pm
by richmond62
La Boîte Diabolique:

https://youtu.be/mE0takm9TX0