简体   繁体   中英

How do I create a file with utf-8 format in lua?

I've created a file with the following code in lua:

local f = io.open("./data/myfile.html", "w") 
f:write(text) 
f:close()

String is stored in the file is Persian. When the file is opened letters are illegible. Like the screenshot below:

image

How I fix it?

Lua doesn't care about encoding. If your Lua source texts are already in utf-8, then you should just add "meta" tag in html "head" section.

<head>
  <meta charset="UTF-8">
</head>

If your html version is earlier than html5, then use older construct:

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM