Jump to content

Strange encoding problem UTF-8


l33cher

Recommended Posts

Hello everybody,

 

I'm posting this here because I'm not sure what the problem is. I have a site and all the files are saved with utf-8 encoding, the database is utf-8 + charset of the page is utf8 + everything seems to work fine. But from time to time when I refresh the page all of the text in the apears like "? ? ? ?" for no reason. It not constantly like this. Most of the time is working fine, but for no reason it just shits up. On my local computer I dont get that problem, but on the server its supposed to be hosted its like this. I'm note sure if it something with the apache configuration ... all of the other sites hosted on this server are cp1251 so nobody actually had the issue before. I cant change the server the site is hosted to. Has anybody seen a problem like this one. Btw the data that i get from the database ALWAYS works fine. The part where the text is from the document buggs but the text from the mysql work fine. I really dont know where to look for the problem.

 

Regards,

l33cher 

Link to comment
Share on other sites

Yes the document is utf-8 10000% sure + yes also make a query "SET NAMES 'utf8'" before anything else. But the problem is not the result i get from the mysql .. it seems fine. The problem is the text thats in the documents sometimes prints out like ? ? ?. Its not constants just from time to time. This happens on all browsers.

Link to comment
Share on other sites

this might be due to your Apache server indeed...

 

if you can not change all the settings, try using

 

ini_set('default_charset', 'UTF-8');

 

at the very beginning of your scripts...

 

this will not affect the other sites hosted on the server

 

Link to comment
Share on other sites

I've experienced similar problems except right at the points where I'm including files (ie. header, menu, footer, side bar etc.) into the main page - at those points I get about 3 strange foreign characters and I've set all mine to UTF-8 as well.

 

Will try this when I get home.

Link to comment
Share on other sites

I've experienced similar problems except right at the points where I'm including files (ie. header, menu, footer, side bar etc.) into the main page - at those points I get about 3 strange foreign characters and I've set all mine to UTF-8 as well.

 

Will try this when I get home.

 

this is because your files are saved in UTF-8 with BOM

the 3 chars you see are the BOM...

 

you should save your files in UTF-8 without BOM

this is rahter easy with, for instance, notepad++

http://notepad-plus.sourceforge.net/uk/site.htm

 

EDIT:

more info on the byte order mark (BOM)

http://en.wikipedia.org/wiki/Byte-order_mark

Link to comment
Share on other sites

Nope .. with the ini_set its still doing the problem. the site is newman-bg.com you can check it out. Needs some refreshes. If you dont understand bulgarian just click on any link you find. The server admin has no idea and frankly i'm in a dead end too ..

Link to comment
Share on other sites

Nope .. with the ini_set its still doing the problem. the site is newman-bg.com you can check it out. Needs some refreshes. If you dont understand bulgarian just click on any link you find. The server admin has no idea and frankly i'm in a dead end too ..

this does only happen in this part right:

 

Актуални декори за интериорни решения

1783 PE

 

Изберете страница:

 

this looks like it is JavaScript...

it looks like it is the JavaScript that is corrupting the chars...

Link to comment
Share on other sites

I've experienced similar problems except right at the points where I'm including files (ie. header, menu, footer, side bar etc.) into the main page - at those points I get about 3 strange foreign characters and I've set all mine to UTF-8 as well.

 

Will try this when I get home.

 

this is because your files are saved in UTF-8 with BOM

the 3 chars you see are the BOM...

 

you should save your files in UTF-8 without BOM

this is rahter easy with, for instance, notepad++

http://notepad-plus.sourceforge.net/uk/site.htm

 

EDIT:

more info on the byte order mark (BOM)

http://en.wikipedia.org/wiki/Byte-order_mark

Thanks - I do indeed use Notepad++ (recently switched from Edit+) and the BOM is enabled - will disable it when I get home from work. I've had it appear in some instances of IE and never FF.

Link to comment
Share on other sites

On other part of the site where there is more static text I remove the include ( cuz its an include from another file) and the same problem still exists. I thought it was the js part but .. when i removed it it still did the same thing.

Link to comment
Share on other sites

On other part of the site where there is more static text I remove the include ( cuz its an include from another file) and the same problem still exists. I thought it was the js part but .. when i removed it it still did the same thing.

 

I had another look at the website...

It does look this is a browser bug...

Link to comment
Share on other sites

On other part of the site where there is more static text I remove the include ( cuz its an include from another file) and the same problem still exists. I thought it was the js part but .. when i removed it it still did the same thing.

 

I had another look at the website...

It does look this is a browser bug...

 

It dose this on all browsers ... ff, ie, chrome ..

Link to comment
Share on other sites

If it's not text from the database, and only text that is hard coded into the page, then the problem is almost definitely the encoding of the document. Can't help you anymore than that though mate. Got a link to the page?

Link to comment
Share on other sites

the problem is definitely coming from the JavaScript though...

 

by going here http://newman-bg.com/special.php?idx=4

and refreshing as hell... I never got the ? ? ? ? ? ? ? ?

 

by the way...

after implementing the "AddCharset utf-8 .js"

you should probably clear the cache of your browser...

 

I got them once when refreshing http://newman-bg.com/special.php?idx=4. But can't seem to make them appear again.

 

To the OP: I was wondering if it had something to do with the encoding not being specified in the snippet http://newman-bg.com/special.php?idx=4 outputs. But I don't know what to do from there..

 

If that special.php part is the the only place the quirk occurs, I believe you could solve it by using HTML entities instead of the Unicode characters:

 

Актуални декори за интериорни решения

 

translates to

 

Актуалнидекоризаинтериорнирешения

Link to comment
Share on other sites

the problem is definitely coming from the JavaScript though...

 

by going here http://newman-bg.com/special.php?idx=4

and refreshing as hell... I never got the ? ? ? ? ? ? ? ?

 

by the way...

after implementing the "AddCharset utf-8 .js"

you should probably clear the cache of your browser...

 

I got them once when refreshing http://newman-bg.com/special.php?idx=4. But can't seem to make them appear again.

 

To the OP: I was wondering if it had something to do with the encoding not being specified in the snippet http://newman-bg.com/special.php?idx=4 outputs. But I don't know what to do from there..

 

If that special.php part is the the only place the quirk occurs, I believe you could solve it by using HTML entities instead of the Unicode characters:

 

Актуални декори за интериорни решения

 

translates to

 

Актуалнидекоризаинтериорнирешения

 

Nope .. the shit aint coming only from special.php .. if u click on ПРОДУКТИ and refresh the page several times u'll see that all of the page gets bugged except the data from the database. I understand that It should be a problem related to the documents encoding, but i dont understand how come it might work for a while and them for no reason bug? And also thing thing wont happen on my localhost .. I think i'll change all the encoding to cp1251 but still ..... someday I might need utf-8 for something and I'll be screwed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.