Web Hosting Talk







View Full Version : PHP + mySQL - mySQL outputting incorrectly...


crEA-tEch
12-08-2009, 01:58 PM
Hi all, im have text in a local database on my laptop.

This outputs fine when run locally, characters such as ' and " are fine. Yet when I upload the same code and database to my webhosting the code outputs things like â instead of '.

The way I call the text is:

<? echo stripslashes(utf8_encode($row['review_website'])); ?>

Im ripping my hair out trying to rectify this but cannot find the problem!!

Any ideas?

Thanks,

Nick

mattle
12-08-2009, 06:25 PM
You may want to ensure that your charsets are the same between DBs...do a "SHOW CREATE TABLE" on your local and remote machines...

01globalnet
12-08-2009, 07:12 PM
Usually, when you create a database on a hosting account using the control panel, the default character set is latin1-swedish.

You should change the collation of the database and each table with phpmyadmin (operations tab).

Make sure you connect to phpmyadmin with the correct collation/character set and when you import your sql file select the correct encoding.

If your webpages are not in utf8, then you have to change the collation when you connect to db with "set names XXX".

crEA-tEch
01-06-2010, 08:41 AM
hey guys!

apologies for the late late reply... but here goes

Ive checked both databases and they are now both on UTF_general_ci (the hosts database was setup to utf_unicode_ci but I have changed it)

The tables are set to latin1_swedish_ci on both databases.

Yet the hosts database is still outputing: On entering ’ instead of '

I have no idea why this is!

Nick

mattle
01-06-2010, 09:19 AM
Just a guess, but could you be dealing with different locale settings between machines?

crEA-tEch
01-06-2010, 09:22 AM
Hmmm interesting.. what do you mean mattle? (apologies for my ignorance :rolleyes:)

mattle
01-06-2010, 09:41 AM
CAVEAT: I don't know a lot about UTF-8 encoding...so hopefully someone will correct me if I'm passing on bad information here...

On UNIX systems, you can type "locale" at a shell prompt to see the information about where your computer thinks it is (and how it will interpret UTF8 encoding).

For example, here's mine from a Solaris machine in the US (not using UTF8, so not the best example)


# locale
LANG=
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=


As I understand it, different locales will reuse the same bytes as different characters... (0xFF might be one character in German and another in Japanese, eg).

Again, I'm probably not the best one to answer this, so hopefully someone will either validate this info or correct it.

crEA-tEch
01-07-2010, 06:36 AM
I have found out what it is!!

My brother is copying and pasting from word, and word uses different characters rather than " and ' ... it uses “ and ’.

I have tried copying from word into notepad, then from notepad into the form on the admin section. But it still doesnt like them as it then turns them into slightly different characters (which i dont know if they will show on this forum - “ and ’.

Is there a way around this? - although Im not greatly keen on adding a bit of code to every variable that passes into the database from PHP :mad:

Does word have a formatting option that will blanket change all characters into different formats?

mattle
01-11-2010, 12:11 PM
I don't know if Word will change characters that are already in the document, but I'm pretty sure there's an option (autoformatting?) to tell it to only use the regular (straight) quotes. When you type the characters, Word receives the regular ASCII quote characters and then replaces them with the curly or angled quotes. I believe you can turn that "feature" off--just don't ask me how!