0

I have used UTF-8 encoding and ASP classic with vbscript as default scripting language in my website. I have separated files to smaller parts for better management.

I always use this trick in first line of separated files to preserve UTF-8 encoding while saving files elsewhere the language characters are converted to weird characters.

mainfile.asp

    <html>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    </head>
    <body>
    <!--#include file="sub.asp"--->
    </body>
    </html>

sub.asp

  <%if 1=2 then%>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <%end if%>
  this is some characters in other language:
  تست متن به زبان فارسی

This trick works good for offline saving and also works good when the page is running on the server because these Extra lines are omitted (because the condition is always false!):

Is there a better way to preserve encoding in separated files?

I use Microsoft expression web for editing files.

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • You what...really? I've banged on about this so many times, to preserve the encoding make sure that you save the physical files with the desired encoding *(in this case UTF-8)* that means both the main asp file and any include files referenced inside it. Then in the main asp file *(not the includes)* specify `<% @CodePage = "65001" %>`. Explain it all here - http://stackoverflow.com/a/21914278/692942 – user692942 Jul 27 '16 at 08:40
  • You talk about that trick working but what if you are writing a structured asp file that doesn't output a HTML page? It's a poor hack at best and depends the browser interpreting the `meta` tag. – user692942 Jul 27 '16 at 08:42
  • Thank you. What you mean by "saving files with desired encoding"? I use Microsoft expression. How do you do that? – Ali Sheikhpour Jul 27 '16 at 09:41
  • 1
    *face palm* - The best advice I can ever give you is work with either notepad or better yet something like Notepad++. Using Microsoft Expression is asking for trouble, it's like the days of FrontPage all over again. You can use Microsoft Visual Studio but even that requires some hoops to display the ["Advanced Save Options"](https://msdn.microsoft.com/en-us/library/66d2abf2(v=vs.100).aspx). – user692942 Jul 27 '16 at 09:44
  • Thank you. It seems I have to switch software... Is there any other solution? – Ali Sheikhpour Jul 27 '16 at 10:19
  • Following [these guidelines](http://stackoverflow.com/a/21914278/692942) is the solution, but you need to have software that allows you to verify what encoding the source files are saved with. – user692942 Jul 27 '16 at 10:24

1 Answers1

0

I use Textpad to ensure that all main files and includes are saved in UTF-8 encoding. Just hit 'Save As' and set the encoding dropdown on the dialog to the one you want.

Keep the meta tag as well because that is still necessary.

Amos Fox
  • 308
  • 1
  • 10