bambinou1980 Posted October 8, 2015 Share Posted October 8, 2015 Hello, I am having a problem. Let's say I have this text: $text = "This is the price in €"; When I encode it: $encoded_text = utf8_encode($text); The output is : This is the price in The Euro sign is missing. Any idea why please? Thank you, Ben Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 8, 2015 Share Posted October 8, 2015 Are you sure that the content of $text is ISO-8859-1-encoded? Because that's what utf8_encode() expects. Quote Link to comment Share on other sites More sharing options...
bambinou1980 Posted October 8, 2015 Author Share Posted October 8, 2015 Hi Jacques, What I am not understanding is that my form where the data is passed has <meta charset="UTF-8"> to the top, is this not enough to change the data to UTF-8 upon submission? Regarding the ISO-8859-1-encoded that you are speaking about, it should not happen if I have <meta charset="UTF-8"> at the top of the page no? Thank you, Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted October 8, 2015 Share Posted October 8, 2015 Character encodings are a bit tricky, because there are many places where things can go wrong. The character encoding of your webpages should be declared in the Content-Type HTTP header. This can either be done by the webserver (which is preferrable) or within PHP: header('Content-Type: text/html; charset=UTF-8'); In addition to that, you might use a <meta> element. This is primarily meant as a fallback mechanism for offline documents (when the HTTP headers are no longer available). Note that the Content-Type header takes precedence over the <meta> element. Also note that the meta character encoding should be declared as early as possible, because browsers will only scan the first few bytes of the document. A good place is right after the opening <head> tag. If you do this, then, yes, both the input and the output will use the UTF-8 encoding. In case you store the data, you must also make sure that the database connection and the database itself use UTF-8. This is not the default. MySQL typically uses “Latin-1” (ISO-8859-1), so that's another common source for errors. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.