0

I am getting output as

FBI believed he had a ‘doomsday device’ 

instead of

FBI believed he had a ‘doomsday device’ 

when i am using

iconv("UTF-8", "ISO-8859-1//IGNORE", $topic); 

output is

FBI believed he had a âdoomsday deviceâ 

I am not using any header or charset in my file.

Update

Got why is this happening

when the UTF-8 series of numbers is interpreted as if it were ISO-8859-1 the output is

’

Explaination

0xE28099 breaks down as 0xE2 (â), 0x80 (€) and 0x99 (™). What was one character in UTF-8 (’) gets mistakenly displayed as three (’) when misinterpreted as ISO-8859-1.

Still no solution to convert it

6
  • 6
    Why not fix the root of the problem instead? See UTF-8 all the way through Commented Dec 6, 2012 at 16:02
  • 1
    Are these string coming from a mysql database? try running this before running the select queries : SET NAMES 'UTF-8' Commented Dec 6, 2012 at 16:05
  • yes these are coming from mysql database. setting to utf8 using procedural style prints blank no data is displayed Commented Dec 6, 2012 at 16:09
  • 1
    It's probably UTF-8 shown in a single-byte encoding like ISO-8859-1. Commented Dec 6, 2012 at 16:18
  • 1
    Should probably be noted that browsers don't really support ISO-8859-1 and that characters like , and are unrepresentable in ISO-8859-1. There is no reason to use ISO-8859-1 over Windows-1252 ever (in this context :P I'm sure it has uses because all the 256 characters are first 256 characters in unicode as well) because it just has useless control characters in place of characters like Commented Dec 6, 2012 at 16:42

1 Answer 1

2

Well the output page is being interpreted in Windows-1252, not ISO-8859-1..

I recommend setting your header charset to utf-8:

In apache config:

AddDefaultCharset utf-8 

Php.ini:

default_charset utf-8 

Manually in php:

header("Content-Type: text/html; charset=utf-8"); 

If you cannot do anything of the above because of some weird reasons, you should then convert into Windows-1252 instead:

iconv("UTF-8", "Windows-1252//IGNORE", $topic); 
Sign up to request clarification or add additional context in comments.

3 Comments

when I did iconv one the third option which is in my question is displayed
@NavneetPandey read carefully, my iconv is different from yours. Your iconv has ISO-8859-1, mine has Windows-1252.
@NavneetPandey You are leaving something out then. You should show full code regarding this.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.