1

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?

3

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

the value of the address is not static but it is stored in mysql for each field. How can i solve saving my php file using UTF-8 encoding?
latin-1 is an educated guess right? until i see the bin2hex($address), i'm not sure what charset OP is using, but it's a charset issue yes
@daniele You need to first know what encoding is used in the DB, then you can use functions like iconv or mb_convert_encoding to convert it.
@hanshenrik Yes, it's a guess, based on lang="en-ca", it is most likely.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.