Welcome to WebmasterWorld Guest from 54.144.77.26

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Encoding of characters problem

’ and displaying on browser

     

TechMan

5:07 am on Oct 7, 2008 (gmt 0)

5+ Year Member



Hi,

I am reading an XML file using PHP's fopen method like following and displaying on my website:

$fh = fopen($myFile, 'r');

When I run it locally on Apache on Windows then it displays fine but after uploading it on another Windows server running IIS it is displaying some weird characters like:

’ is being displayed instead of

I tried using different encoding types like:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>

and

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

but result is the same. What could be the problem?

eeek

6:17 am on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do the http headers look like?

TechMan

6:44 am on Oct 7, 2008 (gmt 0)

5+ Year Member



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

dreamcatcher

7:05 am on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Is it a browser problem? Have you viewed the page in other browsers?

dc

TechMan

7:50 am on Oct 7, 2008 (gmt 0)

5+ Year Member



Yes I have tried IE, FF and Chrome.
The other weird character that is randomly showing is
Other than that rest of the text is fine it's just these two characters not showing properly.

TechMan

7:54 am on Oct 7, 2008 (gmt 0)

5+ Year Member



Ok I found one thing that if I load that page in IE and then right click on it then the encoding is set to "Western European (ISO)". And when I select "Unicode (UTF-8)" then it displays the page correctly.

But the question is why is it showing Western European (ISO) by default when I have define UTF-8 in my web page?

TechMan

8:07 am on Oct 7, 2008 (gmt 0)

5+ Year Member



Another strange thing.

Finding 1
---------
If I view the source code of that page, copy source, then create a new html file on my PC, then paste that code and then double click on that file to view then this time encoding is set to UTF-8 but instead of those weird characters it is now showing square boxes! If I select Western European (ISO) then it displays fine!

Finding 2
---------
If I save the page on my PC from File --> Save As in browser, then double click on it to open then this time it is set to Western European (ISO) with those weird characters displaying. And when I select UTF-8 then it shows boxes instead of this character. The other character which is ’ displays fine as

omoutop

9:28 am on Oct 7, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



have you tried to utf8_encode() the content of the file?
later you can utf8_decode() the content

TechMan

10:26 am on Oct 7, 2008 (gmt 0)

5+ Year Member



I tried utf_encode/decode but didn't work....same result.
For the time being I am replacing with &nbsp; and ’ with ' to make it work but I know that's not the best solution.