PHP - U+FFFD Unicode � error instead of the char

81 views Asked by At

I have tested my website on localhost but once uploaded i see that in the
address is not displayed correctly. The address contains the following errror:

 37 Gr�ce Ave

instead of

37 Grâce Ave,

Here there is the beginning of my html page:

<html lang="en-ca">

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

On localhost the address $address='37 Grâce Ave,' is displayed correctly. I have a lot of addresses with these special chars, how can i fix this error?

1

There are 1 answers

4
shingo On

Save your php file using UTF-8 encoding again, or change the charset to latin-1 (or the one you are currently using) in the head.

To convert a string from one encoding to UTF-8, you can use functions like iconv or mb_convert_encoding.

$address = iconv('encoding-of-the-column', 'utf-8', $address); 

Explanation: Your current file (or the string) should have been saved using one of the european encoding, the value of â is greater than 0x7F, in UTF-8 encoding a single character greater than 0x7F is invalid, so it's displayed as an error character.