homepage Welcome to WebmasterWorld Guest from 107.20.25.215
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Encoding of characters problem
’ and displaying on browser
TechMan




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

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




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

What do the http headers look like?

TechMan




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

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

dreamcatcher




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

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

dc

TechMan




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

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




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

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




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

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




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

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

TechMan




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved