CSS file encoding. Solving problems with incorrect web page encoding

One of the most common problems that a beginner faces Webmaster(and not just beginners), this problems with coding on the site. Even for me it constantly appears when creating websites " 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 just as quickly solve problems related to coding on the site.

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

First reason

The meta tag is written incorrectly content-type. Be careful, it should always contain the encoding in which your document is written.

The second reason

It seems that the meta tag is written the way you want, and the browser displays exactly what you want, but for some reason there are still problems with the encoding. The culprit here is almost certainly that the document itself has different 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 a meta tag UTF-8, and the document itself is written in ANSI, then do the conversion to UTF-8(via menu " Encodings" and point " 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 should come out in the correct encoding.

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

How to set the site encoding so that the browser can correctly determine it, and not show you crap like:

Р-аказать сайт Сѓ нас - это создать сайт недорого ккаче ствеРСРСРѕ

In HTML, the tag is used to indicate the encoding:

The most common encoding types for the Russian language are transmitted in the document header:

Windows-1251 - Cyrillic (Windows).
KOI8-r - Cyrillic (KOI8-R)
cp866 - Cyrillic (DOS).
Windows-1252 - Western Europe (Windows).
Windows-1250 - Central Europe (Windows).
UTF-8 - two-byte encoding

Now let's look at specifying the default encoding through the .htaccess file (if this file does not exist, you need to create it, the file name begins with a dot)

AddDefaultCharset sets the default character table (encoding) for all rendered pages on the Apache web server

Just add 1 line

AddDefaultCharset UTF-8

AddDefaultCharset WINDOWS-1251

Just one line, and the browser will present the page to the user in the correct encoding, regardless of his preferences. The site encoding will be the same for all browsers.

When uploading a file to the server, recoding is possible. We indicate that all received files will have the windows-1251 encoding, we will write for this.

Vlad Merzhevich

Meta tags are used to store information intended for browsers and search engines. For example, search engine engines access meta tags to obtain a description of a site, keywords and other data.

Meta tags for search engines

There is an opinion among website developers that correctly written meta tags allow you to rise to the top of search engines. In fact, this is not true; meta tags alone will not help you rise high, but poorly executed meta tag content can worsen the site’s ranking.

Two meta tags are designed specifically for search engines: description and keywords. Some webmasters added keywords to the keywords section that had nothing to do with the topic of the site, but nevertheless enjoyed some success among search engine visitors. However, after some time, search engines learned to deal with this phenomenon and check the content of a web page for compliance with the stated keywords.

Some principles related to meta tags:

  • do not include keywords that are not contained on your pages;
  • do not repeat keywords;
  • use meta tags for their intended purpose;
  • make the description and list of keywords different for each page of the site, taking into account the content.

description

Most search engines display the contents of the description field (example 1) when displaying search results. If this tag is not on the page, then the search engine will simply list the first words found on the page, which, as a rule, are not very relevant to the topic.

Example 1: Using Description

description

keywords

This meta tag was intended to describe keywords appearing on the page (Example 2). But as a result, the actions of people who want to get to the top of search engines by any means necessary have now been discredited. Therefore, many search engines skip this parameter.

Example 2: Using Keywords

keywords

Keywords can be listed separated by spaces or commas. Search engines They themselves will bring the recording to the form that they use.

Autoloading pages

To automatically download a new document after a certain period of time, use the http-equiv="refresh" instruction (example 3).

. For the Windows operating system and the Cyrillic alphabet, the charset usually takes the value utf-8 or windows-1251 (example 4).

Example 4. Selecting the current encoding

Encoding

Cyrillic



If there is no encoding specified, the browser itself tries to determine what type of characters is used in the document and selects the necessary encoding automatically. The browser may not always accurately recognize the language of a web page and in some cases will suggest Vietnamese encoding instead of Cyrillic. For this reason, it is better to always include the line given. However, there are circumstances where specifying the encoding may cause some harm. For example, the web server automatically uses data transcoding in KOI-8, and the browser, when it encounters the charset=windows-1251 parameter, converts the text to Windows encoding. This results in a double change of characters; it is not easy to read such text. Fortunately, such a problem is already a thing of the past; in any case, it can be easily identified and neutralized at the server level.

15.03.2016

Not yet


Hi all!
Let's continue learning the basics of HTML. In this lesson we will look at how to specify HTML encoding for a site (web page).
This lesson is very important because not knowing how to specify the encoding for a web page can result in your page being unreadable. You ask: “How is it that they can’t?”
Let me show you what my blog looks like with incorrect encoding:

So, HTML encoding– these are tables of correspondence between codes and alphabet symbols. That is, our encoding computer will change the code into clear, readable letters.

To tell the browser what encoding the characters on the web page are in, you need to write between the tags Here's a meta tag:

Please note that the code contains the word “encoding name”. Here you need to specify the HTML encoding.
This is usually utf-8 or windows-1251.

Encoding forutf-8:

EncodingFor windows-1251:

If you forget to tell the browser what encoding a site or web page is in, the browser will try to determine the encoding automatically, but it does not always succeed correctly. In the end, the result will be the same as what I showed in the picture above.

Let's move on to practice.

How to create an HTML document with
utf-8 encoding

“All Programs” => “Accessories” => “Notepad” :

<br> <br> </body> </html> </p><p> <head></head> This is the 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” => “Save as...”</span>:</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-3.png' width="100%" loading=lazy loading=lazy></p> <p><br>Where the item “Encoding:” is specified “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 loading=lazy></p><p>Enlarge the image?</p> <h3><span>How to create an HTML document with windows-1251 encoding</span></h3> <p>Open a standard notepad. <span><i>“All Programs” => “Accessories” => “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> This is the meta tag:</p><p> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> </p><p>This is what it should look like (line #4):</p><p> <html> <head> <title>My first HTML page on StepkinBlog..<br> <br> </body> </html> </p><p>Click in notepad <span>“File” => “Save as...”</span>:</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-5.png' width="100%" loading=lazy loading=lazy></p> <p>Where the “File name” item is, write the name of the web page in Latin and with the extension “.html”. I think you remember this from your first lessons. <br>Where the “Encoding:” item is specified, 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 loading=lazy></p> <p>That's all!</p> <p>Most webmasters choose UTF-8 encoding. I won’t tell you the reasons, because I’m afraid to overload you with information that is not yet needed at your stage of knowledge of HTML.</p> <p>For example, in notepad, 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 loading=lazy></p> <p>Since this is incorrect, 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 entry <br></p> 1. We have a file: Myfile.html. <br>2. You need to save it in Unicode -> UTF-8 encoding. <b>Solution 1.</b> <ol><li>Open Myfile.html in a text editor <b>Notebook</b>.</li><li>Select “Save as...”.</li><li>Select UTF-8 encoding.</li><li>Click the button - Save.</li> </ol><br><img src='https://i1.wp.com/u4ilka.kcbux.ru/Raznoe/image/raz-019-02.png' width="100%" loading=lazy loading=lazy><b>Solution 2.</b> <ol><li>Open Myfile.html in a text editor <b>Notepad++</b>(there is also a PSPad editor)</li><li>Menu -> Encodings. <br>Here we see (Notepad++ determines itself) the encoding of the file we opened.</li><li>Choose <span>Convert to UTF-8 without BOM</span>(BOM - Byte Order Mark). <br>(Codiroaka "UTF-8 without BOM" is preferred and differs from just "UTF-8").</li><li>Menu -> File -> Save.</li> </ol><br><img src='https://i1.wp.com/u4ilka.kcbux.ru/Raznoe/image/raz-019-03.png' width="100%" loading=lazy loading=lazy><h4>Browser encoding detection</h4>We ourselves tell the browser what encoding is set for this HTML file. <br>This is done using the META tag 1) <meta http-equiv="Content-Type" content="text/html; charset=utf-8">The example above instructs the browser that the downloaded HTML file is saved in utf-8 encoding. If the HTML file is saved in windows-1251 encoding, then: 2) <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <b>Important!</b> <br>When transcoding files <b>don't forget to change</b> directives in the META tag to be relevant. <br>If one encoding is specified in the META tag, and the file is saved in another encoding, then we will see “gibberish” on the screen. <p>3) <b>If</b> The META tag contains the required encoding, but the site still displays “abracadabra”, then you need to check the site settings on the hosting (web server). <br>Usually on hosting, the encoding is set to utf-8 in the site settings. <br>If the hosting settings specify the encoding windows-1251, then you need to change the setting to utf-8.</p> <script>document.write("<img style='display:none;' src='//counter.yadro.ru/hit;artfast_after?t44.1;r"+ escape(document.referrer)+((typeof(screen)=="undefined")?"": ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth? screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+ ";"+Math.random()+ "border='0' width='1' height='1' loading=lazy loading=lazy>");</script> <div style="clear:both;"></div> </div> <script type="text/javascript" src="https://fighters.ru/wp-content/themes/cehla_mgomz/js/orphus.js"></script> </article> </div> <aside id="sidebar"> <div id="primary" class="widget-area" role="complementary"> <ul class="xoxo"> <li id="categoryposts-2" class="block widget-container widget_categoryposts"><h3 class="widget-title"><a href="https://fighters.ru/en/">The last notes</a></h3><ul> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/chto-takoe-rasshirenie-faila-ios-kak-otkryt-djvu-faily-v-ios-iphone-ipad-ipod-touch-format/" rel="bookmark">How to open DJVU files in iOS (iPhone, iPad, iPod Touch) Application format for ios</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/chastnyi-dostup-na-kompyutere-kak-bystro-vklyuchit-ili-otklyuchit/" rel="bookmark">How to quickly enable or disable private browsing in Safari</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/exif-tehnicheskie-dannye-fotografii-kak-ih-posmotret-i-udalit/" rel="bookmark">Technical data of a photo: how to view and delete them</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/kak-naiti-pohozhuyu-kartinku-fotografiyu-izobrazhenie-v-internet/" rel="bookmark">How to find out exactly the shooting location and hide your location How to find out the location from a photograph</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/chto-takoe-cikly-perezaryadki-macbook-i-na-skolko-ih-hvatit-kak-proverit/" rel="bookmark">How to Check MacBook Battery Charge Cycles and Capacity How to Extend Battery Life</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/kak-skryt-faily-na-mac-os-x-kak-ustanovit-parol-na-papku-v-mac-os-x/" rel="bookmark">How to set a password for a folder in Mac OS X, and how to protect information from prying eyes How to hide mac os system files</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/kak-sdelat-na-aifone-chto-kak-iz-android-smartfona-sdelat-ios-zashchita-ot/" rel="bookmark">How to turn an Android smartphone into iOS</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/polnyi-stek-lineinoi-pehoty-ili-proshchai-kavaleriya-diplomatiya-v/" rel="bookmark">Diplomacy in Empire Total War</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/pochemu-net-botov-v-ks-i-kak-ih-vklyuchit-instrukciya-pochemu-net-botov-v-ks-i/" rel="bookmark">Why there are no bots in CS and how to enable them - instructions How to create bots CS 1</a> </li> <li class="cat-post-item"> <a class="post-title" href="https://fighters.ru/en/prohozhdenie-korsary-kazhdomu-svo-pogruzhenie-prohozhdenie-igry-korsary/" rel="bookmark">Walkthrough Corsairs: To Each His Own</a> </li> </ul> </li> </ul> </div> <div id="secondary" class="widget-area" role="complementary"> </div> </aside> </div> <div style="clear:both;"></div> </div> <br> <footer id="footer" role="contentinfo" class="clearfix"> <div id="footer-in"> <div id="colophon"> <div id="footer-widget-area" role="complementary"> <div id="first" class="widget-area"> </div> <div id="second" class="widget-area"> <ul class="xoxo"> <li id="linkcat-58" class="block widget-container widget_links"> <h3 class="widget-title">We are in social networks</h3> <ul class='xoxo blogroll'> <li><a href="https://www.facebook.com/sharer/sharer.php?u=https://fighters.ru/kodirovka-css-faila-reshenie-problem-nepravilnoi-kodirovkoi-veb-stranicy/" title="" target="_blank">Facebook</a></li> <li><a href="" title="Instagram">Instagram</a></li> <li><a href="https://www.twitter.com/share?url=https%3A%2F%2Ffighters.ru%2Fen%2Fkodirovka-css-faila-reshenie-problem-nepravilnoi-kodirovkoi-veb-stranicy" title="Twitter" target="_blank">Twitter</a></li> <li><a href="https://vk.com/share.php?url=https://fighters.ru/kodirovka-css-faila-reshenie-problem-nepravilnoi-kodirovkoi-veb-stranicy/" target="_blank">In contact with</a></li> </ul> </li> </ul> </div> <div id="third" class="widget-area"> <ul class="xoxo"> <li id="linkcat-2" class="block widget-container widget_links"> <h3 class="widget-title">Categories</h3> <ul class='xoxo blogroll'> <li><a href="https://fighters.ru/en/category/internet/">Internet</a></li> <li><a href="https://fighters.ru/en/category/programs/">Programs</a></li> <li><a href="https://fighters.ru/en/category/instructions/">Instructions</a></li> <li><a href="https://fighters.ru/en/category/windows/">Windows</a></li> <li><a href="https://fighters.ru/en/category/computers/">Computers</a></li> </ul> </li> </ul> </div> </div> </div> <div id="site-info">Copyright fighters.ru</div> </div> </footer> <script type='text/javascript' src='https://fighters.ru/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=4.8'></script> <script type='text/javascript' src='/wp-includes/js/wp-embed.min.js?ver=4.8.4'></script> <br> <br> </body> </html>