weyhei
weyhei

Reputation: 479

What code to use related to PHP Encoding?

How do I interpret some characters into their proper form in PHP?

For example, the string is \u00c9rwin but PHP print it as Érwin, and the correct form must be Érwin

What is the proper PHP code for this? I am pretty sure this is not an HTML entity, or is it?

P.S. no encoding was declared on the PHP file

Upvotes: 1

Views: 63

Answers (2)

mgraph
mgraph

Reputation: 15338

add this in header:

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

or:

<?php header ('Content-type: text/html; charset=utf-8'); ?>

Upvotes: 1

user1226700
user1226700

Reputation:

Look into utf8_encode and utf8_decode. It's important as well to go UTF8 across the whole stack. What that means is that your database connection should be using UTF8 (here's how in MySQL), your HTTP Content-Type should be returning UTF8 (see mgraph's example below) and you should also be setting it in the meta tag so that there is no need to encode/decode at all as you're using the same charset everywhere.

Upvotes: 2

Related Questions