Weird characters in text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siko
Forum Commoner
Posts: 37
Joined: Tue Feb 16, 2010 11:28 pm

Weird characters in text

Post by siko »

Hi there,

I am rather new to PHP (to web programming actually), I am have a problem handling my text fields.

When I store a text field into mysql database and then retrieving them back, they are displaying weird characters like these

Image

and

Image

I am using htmlentities($field) before storing the data into mysql, and when I display the text with or without nl2br(html_entity_decode($field)), the characters are appearing that way.

I have copied those characters and pasted them into blogs like blogspot to look at the post and see what exactly those characters are, and realise that some of those characters are actually 'nothing', i.e. they are not expressed (simply not there).

I have tried changing between UTF-8 and ISO-8859-1 charsets but it seems they are not the solution to the problem (or maybe it had nothing to do with it.. I'm just trying everything..)

I have some thoughts that perhaps it may be the language of the user's computer/keyboard, but it is hard for me to test as I cannot get the users who had such problems input something again - my site is running live on the web and random people are coming in.

Does anyone have any advice?
nblackwood
Forum Newbie
Posts: 4
Joined: Wed Feb 17, 2010 2:12 am

Re: Weird characters in text

Post by nblackwood »

can you give a sample of the code you are using?
dejvos
Forum Contributor
Posts: 122
Joined: Tue Mar 10, 2009 8:40 am

Re: Weird characters in text

Post by dejvos »

This usually occures when you have a bad charset in the column of database. I've this experience when I wanted to save UTF-8 text into a column which is in latin1 for example.

So you need to change a charset of the column in the db.

Good luck!
Post Reply