Wednesday 22 August 2018

html - Can I make browsers choose UTF-8 for viewing source code?

I put up some source code files for viewing on the web. The problem is, browsers tend to not understand that these files are in UTF-8, and I wonder if there's anything I can do about that. (I'm sure some browsers use UTF-8 per default, but Safari at least doesn't. I have to go into the View menu and choose the encoding manually to make it look right.)


My set of webpages is here, with several Python files and one C file: fgcode.avadeaux.net. I tried putting a charset="UTF-8" attribute in the a elements in the , but that doesn't seem to help. The Python files declare the charset in a comment on the top line, but the browser ignores that as well (which is no surprise, it's not a Python source code browser after all).


I don't have much control over the web server, it's run by my ISP and I just put the files there. But I'd still be interested to know if this problem has a web server configuration solution.


Solution: solved, as per links provided, by adding an .htaccess file with the following content:


AddDefaultCharset UTF-8
AddCharset UTF-8 .py
AddCharset UTF-8 .c

Only the first line wasn't enough in my case.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...