Convert string to utf-8

3

I need to transform a string into UTF-8 encoding. I'm stating it like this:

$nome = utf8_encode($nome);

And yet I can not find the error.

The string looks like this:

Consolação
    
asked by anonymous 26.02.2014 / 20:50

3 answers

6

If you are experiencing browser problems, you are probably using the wrong encode.

Add the header <meta charset="utf-8" /> to the head section of your page, as follows:

<html lang="pt-br">
<head>
    <meta charset="utf-8" />

Preferably place it at the beginning, preferably before the <title> tag, which can usually be changed by the user, as in a search. Security holes can occur in older browsers if this is not followed ( source ).

    
26.02.2014 / 21:02
3

Apparently the conversion worked out well or was done twice. What can happen is that the page is being displayed in another encoding. Try placing

<meta charset="UTF-8" />

no <head> of the page and see if it appears correctly.

Alternatively, you can use htmlentities() to display, not depend on the encoding for the screen.

$nome_para_display_na_tela = htmlentities($nome);

Remembering that anyway, you will always need the right encoding for the database.

    
26.02.2014 / 21:01
1

I use a combination of things, for example in php I put

header("Content-Type: text/html; charset=UTF-8",true);

and in html within head tags

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
26.02.2014 / 21:18