0

I copy pasted a certain paragraph from another site and the outcome had question marks in it such as

animal�ideally 

My server is set to iso-8859-1 apparently and my meta tag is saying set charset to utf-8.

I have never worked with charsets and don't know what it is besides what I've been researching about it.

If I exit the content out of the database or directly upon submission it contains the ? marks. What is the procedure or course of action I must take to make these question marks disappear?

REading other posts said in mysql_query do

   mysql_query("SET NAMES 'UTF8');

I did that, and it still didn't help.

What do I do ? Thank you.

Darius
  • 1,613
  • 5
  • 29
  • 58
  • 1
    If your server "is set to iso-8859-1" and says "utf-8" there could be some problems. Set server encoding to UTF8 too. – s.webbandit May 26 '12 at 08:05
  • 2
    Make sure to read [Handling Unicode Front To Back in a Web App](http://kunststube.net/frontback/). I'm guessing you need to explicitly send the `Content-Type: text/html;charset=utf-8` header from your code. – DCoder May 26 '12 at 08:05
  • try changing collation to utf8_bin – swapnesh May 26 '12 at 08:06
  • 1
    When your say your `server is set to iso-8859-1`, where exactly is that set? If you `copy pasted a certain paragraph from another site`, where did you paste it into? It sounds like your *editor* is set to IS-8859-1, and that is where you need to change your encoding - probably you want UTF-8 *without [BOM](http://en.wikipedia.org/wiki/Byte_order_mark)*. If you do this, the browser should respect your meta tag - but with your editor set to the wrong encoding the document stored on the server will be invalid. – DaveRandom May 26 '12 at 08:10
  • Your code here is missing a " – eric.itzhak May 26 '12 at 08:17
  • Thank eric, I typed that in here without double checking, it had the " when doing it though. @DaveRandom, the charset in phpinfo, that's where it's set, and mbstring or something of the sort if I remember correctly. – Darius May 26 '12 at 23:10

2 Answers2

1

to show UTF8 characters in your page you need to set the charset for your page:

<meta charset="utf-8">

if you want to save such characters into database, database be UTF8 also:

CREATE TABLE foo
(
   id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
   ...
 ) CHARACTER SET utf8 COLLATE utf8_general_ci

you'll also need to set the php for utf8: (at top)

header("Content-Type: text/html; charset=UTF-8\n");
  • Thank you for the reply. Turns out the issue is that I ran htmlentities on the data before putting it into the database, which breaks it. For some reason it doesn't know how to reinterpret it back from htmlentities, any solution for that? – Darius May 27 '12 at 08:01
  • why do you call htmlentities? is there a reason to convert all applicable characters to their x; like values? If you want the reverse you can call html_entity_decode($data) on your string to put them back. –  May 27 '12 at 08:11
  • Great tip, thanks. I was using htmlentities which broke the utf8 stuff and htmlspecialchars worked along with your fix. I didn't know htmlentities wasn't necessary when trying to protect user input content :D – Darius May 27 '12 at 10:49
1

If you are using phpmyadmin you need to change Character Set as utf8_general_ci. You can visit this page: Change default Charset

Community
  • 1
  • 1
Birlikisgu
  • 227
  • 1
  • 3
  • 9