Html write encoding for older browsers. HTML encoding. What encoding to save the web page to. Incorrect HTML page encoding

One of the most common problems with a website is its encoding. And despite this, many Webmasters continue to argue that the browser chooses the encoding itself. Indeed, he chooses the encoding himself, but he does not always do it correctly. This is the most common encoding error: a site in an encoding, for example, UTF-8, and the browser persistently selects windows-1251... Here how to hardcoding via htaccess file, I will explain in this short article.

In order to set file encoding in htaccess just write one line in it:

AddDefaultCharset UTF-8

If you need windows-1251then so:

AddDefaultCharset WINDOWS-1251

Just one line and now the browser, regardless of its preference, will choose the specified encoding. I say right away that this method is really powerful. You must understand that since the browser does not correctly recognize the encoding of your site (even ignoring the meta tag " ContentType"), then there are reasons for this, so check carefully: everything is displayed well everywhere.

I hope that with this article I helped you solve the problem with the encoding. And in the next article I will talk about the problem related to database encoding... This is also a very common problem that many cannot solve.

1. We have a file: Myfile.html.
2. It is necessary to save it in Unicode encoding -\u003e UTF-8. Solution 1.
  1. Open Myfile.html in a text editor Notebook.
  2. We select "Save as ...".
  3. Choosing UTF-8 encoding.
  4. We press the button - Save.

Solution 2.
  1. Open Myfile.html in a text editor Notepad ++ (there is still a PSPad editor)
  2. Menu -\u003e Encodings.
    Here we see (Notepad ++ determines itself) the encoding of the file we opened.
  3. We choose Convert to UTF-8 without BOM (BOM - Byte Order Mark).
    (Kodiroaka "UTF-8 without BOM" is preferred and different from just "UTF-8").
  4. Menu -\u003e File -\u003e Save.

Detecting encoding by browsers

We ourselves tell the browser what encoding is set for this HTML file.
This is done using the META tag 1) This example instructs the browser that the uploaded HTML file is saved in utf-8 encoding. If the HTML file is saved in windows-1251 encoding, then: 2) Important!
When transcoding files don't forget to change directives in the META tag to the actual ones.
If one encoding is specified in the META tag, and the file is saved in a different encoding, then we will see "gibberish" on the screen.

3) If the required encoding is specified in the META-tag, but the site still displays "gibberish", then you need to check the site settings on the hosting (web server).
Usually, the hosting site has utf-8 encoding specified in the site settings.
If the encoding windows-1251 is specified in the hosting settings, then you need to change the setting to utf-8.

One of the most common problems faced by a beginner Webmaster (and not only beginners), this problems with encoding on the site... Even I constantly appear when creating sites " abracadabra"But, fortunately, I know perfectly well how to solve this problem, so I put everything in order within a few seconds. And in this article I will try to teach you as quickly solve problems related to encoding on the site.

The first thing worth noting is that all the problems with the appearance of "gibberish" are associated with a mismatch between the document encoding and the encoding set by the browser. Let's say a document in windows-1251, and the browser for some reason exposes UTF-8... And already the following reasons may be the source of such discrepancy.

First reason

Incorrectly spelled meta tag content-type... Be careful, it must always contain the encoding in which your document is written.

The second reason

It seems that the meta tag is spelled out the way you want, and the browser displays exactly what you want, but for some reason there is still a problem with the encoding. Here, almost certainly, the fault is that the document itself has an excellent encoding. If you work in Notepad ++, then at the bottom right there is the name of the encoding of the current document (for example, ANSI). If you put in the meta tag UTF-8and the document itself is written in ANSIthen do the conversion to UTF-8 (via the menu " Encodings"and item" Convert to UTF-8 without BOM").

Third reason

Fourth reason

And finally, the last popular reason is problem with encoding in the database... First, make sure that all your tables and fields are written in the same encoding, which matches the encoding of the rest of the site. If this does not help, then immediately after connecting in the script, run the following request:

SET NAMES "utf8"

Instead of " utf8"there may be a different encoding. After that, all data from the database must come out in the correct encoding.

In this article, I hope I have disassembled at least 90% of the problems associated with the appearance of "abracadabra" on the site... Now you have to deal with such a popular and simple problem as incorrect encoding in no time.

15.03.2016

not yet


Hello!
We continue to learn the basics of HTML. In this lesson we will analyze how to specify HTML encoding for the site (web page).
This lesson is very important, as not knowing how to specify the encoding for a web page can result in your page being unreadable. You ask: "How so, they will not be able to?"
Let me show you what my blog looks like with the wrong encoding:

So, HTML encoding Are tables of correspondence of codes and symbols of the alphabet. That is, our computer will change the encoding code to understandable readable letters.

To tell the browser what encoding the characters of the web page are in, you need to write between the tags this is the meta tag:

Please note that the code contains the word "encoding name". Here you need to specify the HTML encoding.
Usually it is utf-8 or windows-1251.

Encoding forutf-8:

Encoding for windows-1251:

If you forget to tell the browser what encoding the site or web page is in, the browser will try to determine the encoding automatically, but it doesn't always work out correctly. As a result, the result will be the same as I showed in the picture above.

Let's get down to practice.

How to create an HTML document with
utf-8 encoding

"All Programs" \u003d\u003e "Standard" \u003d\u003e "Notepad" :

<br> <br> </body> </html> </p><p> <head></head> here is this meta tag:</p><p> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </p><p> <html> <head> <title> My first HTML page on StepkinBlog ..<br> <br> </body> </html> </p><p>Click in notepad <span>"File" \u003d\u003e "Save as ..."</span>:</p> <p><img src='https://i0.wp.com/stepkinblog.ru/wp-content/uploads/2016/03/kak-ukazat-kodirovku-sajta-na-html-osnovy-html-dlya-nachinayushhix-urok-20-3.png' width="100%" loading=lazy></p> <p><br> Where the item "Encoding:" indicate "UTF-8". <br> Click "Save":</p> <p><img src='https://i2.wp.com/stepkinblog.ru/wp-content/uploads/2016/03/kak-ukazat-kodirovku-sajta-na-html-osnovy-html-dlya-nachinayushhix-urok-20-4.png' width="100%" loading=lazy></p><p>Enlarge image?</p> <h3><span>How to create HTML document with windows-1251 encoding</span></h3> <p>Open your standard notepad. <span><i>"All Programs" \u003d\u003e "Standard" \u003d\u003e "Notepad"</i> </span>.<br> Next, paste the standard HTML code into notepad:</p><p> <html> <head> <title> My first HTML page on StepkinBlog ..<br> <br> </body> </html> </p><p>Now we indicate in what encoding the web page is saved. To do this, place between tags <head></head> here is this meta tag:</p><p> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </p><p>This is how it should look like (line number 4):</p><p> <html> <head> <title> My first HTML page on StepkinBlog ..<br> <br> </body> </html> </p><p>Click in notepad <span>"File" \u003d\u003e "Save as ..."</span>:</p> <p><img src='https://i1.wp.com/stepkinblog.ru/wp-content/uploads/2016/03/kak-ukazat-kodirovku-sajta-na-html-osnovy-html-dlya-nachinayushhix-urok-20-5.png' width="100%" loading=lazy></p> <p>Where the item "File name" write the name of the web page in Latin and with the extension ".html". I think you remember this from the very first lessons. <br> Where the item "Encoding:" indicate "ANSI". <br> Click "Save":</p> <p><img src='https://i0.wp.com/stepkinblog.ru/wp-content/uploads/2016/03/kak-ukazat-kodirovku-sajta-na-html-osnovy-html-dlya-nachinayushhix-urok-20-6.png' width="100%" loading=lazy></p> <p>That's all!</p> <p>Most webmasters choose UTF-8 encoding. I will not tell you the reasons, because I am afraid to load you with information that is not yet needed at your stage of learning HTML.</p> <p>For example, in the blockchain, set the code:</p><p> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </p><p>And specify "ANSI" when saving:</p> <p><img src='https://i0.wp.com/stepkinblog.ru/wp-content/uploads/2016/03/kak-ukazat-kodirovku-sajta-na-html-osnovy-html-dlya-nachinayushhix-urok-20-6.png' width="100%" loading=lazy></p> <p>Since this is wrong, the result will be like this:</p> <p>Save your web pages correctly to avoid results like this</p> <p>Previous post <br></span> <span>Next post <br></p> <p>When creating a website, novice webmasters often have questions: what encoding to use for the website, how UTF-8 differs from windows-1251, and how to write it in META Charset of the website's HTML page. The answers to all these questions are in this article.</p> <h2>What is site encoding and how does it work</h2> <p>The encoding can be represented as a table consisting of different letters, numbers and other human-readable characters, which are encoded in a certain way. When you open a text file, which include HTML pages, the computer reads from the file header in what encoding it was saved and outputs the text in the appropriate encoding converting computer data into a human-readable form comparing this data with the encoding table. If the information about the encoding from the file header matches the encoding in which the data is stored in the HTML page, then the user sees the letters, numbers and other symbols familiar to him. If there is a mismatch, then the result is an incomprehensible set of characters to the user, especially often in old email programs. If the user received a letter with incomprehensible kryakozyabras, then simply by sorting through different encodings, it usually turns out to guess and select the one in which the letter is written, and as a result, an incomprehensible set of characters turns into a human-readable text.</p> <p>The same thing happens with the HTML pages of the site. If the document was saved, for example, in UTF-8 encoding, and the document itself contains a META tag indicating that this is windows-1251 encoding, then the browser will again compare the data saved in the file with the table of the encoding specified to it, and since the characters are encoded by - differently, the browser will display an incomprehensible set of characters instead of the usual text, or some of the letters may be in normal form, and other letters or symbols may be displayed, for example, in the form of question marks. All of the above applies also to the display of file names.</p> <p>When creating a new document in a text editor, it is better to immediately make sure that the desired encoding is selected. Modern editors allow you to convert the text of an open document from one encoding to another, and standard Notepad allows you to choose an encoding only when you save the file.</p> <h2>The most common encodings</h2> <p>From the previous paragraph, you already know what an encoding is and why it is so important to correctly register it in the code of the site pages. Let's now find out which of the many encodings is better to choose for the future site. Since the Windows operating system has always been the most common and most understandable to learn, most web developers created HTML pages in windows-1251 (ANSI) encoding, which was used by default. But windows-1251 does not support a very large number of letters and symbols, and developers want to use various arrows, hearts, squares and other symbols in their texts, including the need to combine words from different languages \u200b\u200bin one document, so it has been replaced for a long time more extended UTF-8 has come and most developers use this encoding.</p> <h2>Encoding issues not only in the HTML page</h2> <p>A site, whether it is just a collection of static HTML documents or complex dynamic scripts that generate pages on the fly, is hosted on a web server that also works with a specific encoding. And if the server issues information in one encoding, and your pages or scripts are saved in a different encoding, then again, there may be problems with displaying pages in the user's browser. Many hosting providers allow you to change the settings and select the encoding in accordance with the one used in the site files through the control panel, or register it in the .htaccess file if the hosting uses the popular Apache web server.</p> <p>Almost no modern website is complete without using a MySQL database, and it can also become a source of encoding problems. If the site files are stored in one encoding, and the information in the database in another, then on the page that part of the information that is output from the database can be displayed in the form of all the same question marks or other incomprehensible symbols. To avoid problems with encoding, it must be the same for the web server, MySQL database, scripts, HTML pages of the site and in the META tag that is written in the HTML code. If there are problems with the display of text, then check for the problem of all of the above.</p> <h2>META Charset HTML Document</h2> <p>To tell the browser and search engines what encoding the site pages are stored in, META Charset is written in their code.</p> <p>For windows-1251 encoding:</p> <span><!DOCTYPE html> <html lang="ru"> <head> <title>Page title

Page text




For UTF-8 encoding:

Page title

Page text




Now you know what site encoding is and where to look for problems if text is displayed incorrectly in any part of the site.

Copying of the article is prohibited.

Did you like the article? To share with friends: