1
I developed a website and when I use:
header("Content-Type: text/html; charset=utf-8", true);
PHP characters work perfectly, but HTML characters don’t, you get question marks. But when I use the code below, it happens exactly the opposite, that is, it works normal in HTML but not in PHP:
header("Content-Type: text/html; charset=ISO-8859-1", true);
Can someone please help me?
In the
html
place<meta charset="UTF-8">
within thehead
, so utf-8 will work at 2– Brumazzi DB
You are saving the HTML with the wrong encoding, that’s all. The problem is in the configuration of the source editor. Which editor are you using? Hit the editor’s encoding to match what you want to use, before saving the code, or use entities, which are independent of encoding. It’s one of the most well-thought-out things in HTML, and it doesn’t change with any encoding, although if one dominates what one is doing and has control over the environment, it may be unnecessary.
– Bacco
It is not possible to determine a solution without analyzing its files. For it may be what Bacco commented on as well as can be data coming from a database or other source (txt, json, etc.) that are charset iso.. But do the most basic and simple, checking how your text editor is saving the files, both php and html. Just avoid trying to solve this with htmlentities() or utf8_encode().
– Daniel Omine
@Danielomine remembering that utf8_encode() is a function of adapting systems in different encodings. In a normal site this should not be used. The reason utf8_encode and utf8_decode exist is only compatibilization when you have no control over any of the parts. If the application is entire yours, it is probably the case of data conversion at source (work with everything in the same encoding), and not in the stream. As for entities, I like it, but when the data source has problems, it can confuse even more (pq html_entities depends on the right encoding).
– Bacco
Now, using entities in HTML I find practical (literal, writing for example
acentuação
instead ofacentuação
), 'cause in that case, since it’s not conversion, it looks good on any encoding.– Bacco