Error in file or character encoding

2

On every page of a website that I'm developing with UTF-8 encoding, defined both in charset and as editor encoding, I'm having trouble in rendering accented words, for example:

The word Medical renders as Doctor .

Considering that I am testing on my localhost , I use PHP and the problem persists in all browsers I tested, how can I resolve this problem?

    
asked by anonymous 21.11.2015 / 22:11

3 answers

2

I usually do this:

  • In PHP codes, use at the top of Index the code header('Content-Type: text/html; charset=utf-8');
  • In HTML, put <meta charset="UTF-8">
  • In your editor, crop all the content, change the encoding of the file to (UTF-8 without BOM), and then paste the content again.
  • If you are using PDOs along with MySQL, you can use this parameter when building your connection: PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
  • Take the custom to always create unneeded UTF-8 files from scratch - See here

This should solve your problem in 99% of cases.

    
22.11.2015 / 14:41
2

The problem may be related to both the file encoding and some error in the output of your PHP.

Start by changing / configuring the encoding of the file by opening it in your IDE by changing the encoding option (or encoding in Portuguese) to UTF-8. Below are the step-by-step two editors that I believe are the most used by current professionals in the market and dev. beginners:

If you use Sublime text you can change by going to:

File - > reopen with enconding - > UTF-8 (English)

Archive - > reopen with encoding - > UTF-8 (Portuguese)

If you use Notepad :

Encoding - > Convert to UTF-8

Encoding - > Convert to UTF-8 (Portuguese)

For other IDE's you can consult its documentation.

After doing the above step, verify that in PHP you are using exactly header('Content-Type: text/html; charset=utf-8'); .

Also check using a debug tool (such as Google's Dev Tools ) if your output is exactly that : <meta charset="UTF-8"> , without any character. For some time now I have read a text that says about this charset need to be in the first 512kb of the document to avoid some bugs in some browsers . Unfortunately I could not find the link for you to take a look and I also believe that the problem related to this already must be solved, however, only for guarantee I recommend that you place between the 1st and 3rd line of your file, I usually put it after the % with% being in the first line after opening <meta http-equiv="X-UA-Compatible" content="IE=Edge"> .

Well, if after all this your problem persists, it can also be a byte-order mark ) being related to ASCII, usually caused by copies by copy and paste also known as CTRL + V and CTRL + C, I talked about it #. Page 92 To simplify, to solve you can open the file in a basic editor (for example the windows text editor) that does not interpret unicode or one that interprets but can display non-ASCII characters and delete the code snippet with problem retyping the same.

Finally, the MySQL connection may also be related if you use this response from the Jpsy user in the OS. You can resolve by assigning <head> to the PDO builder call.

    
22.11.2015 / 15:09
1

Open the file in Notepad ++ and change its encoding (encoding): Encoding -> Convert to UTF-8 or Codificação -> Converter para UTF-8 . If you do not want (or can not) download Notepad ++, this should be done in your IDE.

    
22.11.2015 / 01:08