UTF8 on LC server
mark at livecode.com
Fri Jun 1 07:15:30 EDT 2018
On 2018-06-01 12:53, Tim Selander via use-livecode wrote:
> Hi Mark,
> Here is the script. The files I'm using are
> bamboobabies.com/getjapanesetext.lc, and the text it is getting is
> In the script, there are two lines reading the text file that I've
> taken turns commenting out....
> If you can give me any hints, it would be greatly appreciated.
> Tim Selander
> <?lc put header "Content-Type: text/html; charset=UTF-8" ?>
> <!DOCTYPE HTML>
> <meta http-equiv="Content-type" content="text/html;
> --This line loads readable japanese text, but putting char 500 to 550
> breaks beginning and ending kanji
> put url "http://bamboobabies.com/news.txt" into vText
> --When this line is used, none of the put text is readable
> --put textDecode(url "binfile:bamboobabies.com/news.txt", "utf-8") into
> put line 1 of vText
> put "<BR><BR><BR><BR>"
> put char 500 to 550 of vText
<?lc set the outputTextEncoding to "utf-8" ?>
<?lc put header "Content-Type: text/html; charset=UTF-8" ?>
<meta http-equiv="Content-type" content="text/html;
--This line loads readable japanese text, but putting char 500 to 550
breaks beginning and ending kanji
put textDecode(url "http://bamboobabies.com/news.txt", "utf-8") into
put line 1 of vText
put char 500 to 550 of vText
The problem you are having is that your text-file is UTF-8, but the
engine doesn't know that - you need to explicit decode it into a
LiveCode string using textDecode. You can then manipulate it as chars
etc. correctly with Unicode. That solves the 'getting data into livecode
in the form needed' problem.
The other side of the problem is the text encoding used when you do
'put'. By default this is 'native' - by setting the outputTextEncoding
at the start, the engine will automatically encode any strings you 'put'
with the encoding specified.
Hope this helps!
Mark Waddingham ~ mark at livecode.com ~ http://www.livecode.com/
LiveCode: Everyone can create apps
More information about the Use-livecode