1

In one array there's a variable that has an é in it. I tried to replace it with a normal e using

echo strtr($var, "é", "e"); 

but even that doesn't work. It's weird. At the top of my page there's

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

then when I load the page the é character gets converted to [[#233]] and a plugin to convert things to pdf is saying to me that the document contains invalid UTF-8 character(s). Anyone got a clue? The variable between comes from a latin1_swedish_ci database field.

3
  • Where are you getting that character from? If browser input, check if the content encoding is truly set to UTF-8 (usually in the browser's menu). If from MySQL, make sure you have the proper collation on tables and columns, and run this query SET NAMES utf8; before all other queries. Commented Sep 17, 2012 at 7:18
  • I solved it by changing latin1 to utf-8 unicode. I dumped the file, manually changed the encoding of the weird looking characters using notepadd++ and then loaded it up again via Workbench. Commented Sep 17, 2012 at 8:04
  • Yogi answered correctly to your question, so keep in mind to accept useful answers if you want keep a good accept-rate. Or people might not answer any more to your questions Commented Sep 18, 2012 at 15:33

5 Answers 5

2

That é being 00E9 sounds like Windows-1252 (CP1252). Not in the control range but I've had similar issues. Could use iconv to convert it and ensure valid UTF-8.

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

3 Comments

Do you got any clue from which encoding i need to convert it from? I tried iconv('ISO-8859-1//TRANSLIT//IGNORE', 'UTF-8', $var) but that doesn't work. @ficuscr
Give this a try. iconv('Windows-1252', 'UTF-8//TRANSLIT', $text). You can use mb_detect_encoding too. Useful functions to put together.
Thanks bro but that one didn't work as well. I just changed the db fields encoding to utf-8 and changed the weird looking characters. Now it works
2

Before any query (select/insert/update) call this statement:

SET NAMES utf8; 

Maybe you will need re-create your data in DB. Try to insert some new records and selected them.

Comments

1

Please check in database, In which Format é stored. if It Stored in this

&egrave; &#232; &#xE8; 

format than you have to replace with this code.

Comments

1

It could be that your array was written in a file that was not encoded in UTF-8. The discrepancy between your page encoding and the encoding announced with the meta tag causes problem. Make sure you've got the right encoding configured in your text editor or IDE.

Comments

1

just add $html = iconv("UTF-8","UTF-8//IGNORE",$html); and pass this $html to your view

1 Comment

Worked for me but no idea why :P

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.