0

I have a JTextArea from which I get the text, and send it through a POST request to a PHP page, which uses PDO and a prepare statement to insert the text into a MySQL database. This works for everything that I can type directly into the JTextArea. However, it doesn't work when I copy and paste something from Word, for example, into the JTextArea and then upload it.

For example, if I type into Word: "This is a super—long dash." Then copy and paste that in the JTextArea and have it send to the PHP page, which will upload it to the MySQL server, when I get the information back from the MySQL server (using another PHP page) it comes back as "This is a super—long dash."

This also happens for other various special characters, not just long dashes.

Is there anything I can do about this?

EDIT:

I tried to correct the issue by making sure all my php files are using utf8 to connect to mysql like so:

"mysql:host=$servername;dbname=$dbname;charset=utf8"

I also use

echo $_POST[xxx];

To make sure the text is coming in from java correctly, which it is. When I check what is the mysql database, it shows as "This is a superùlong dash". I tried to correct this by using the fixUTF8 function in the solution here: Detect encoding and make everything UTF-8 by Sebastián Grignoli. However, as a result I get "This is a super?long dash".

Community
  • 1
  • 1
Infamous911
  • 1,441
  • 2
  • 26
  • 41
  • Sure it can; you just need to make sure your char encoding is setup properly across the various systems – kolossus Jul 28 '15 at 15:16
  • character set issue. make sure you have the SAME charset at all stages of the rendering pipeline. – Marc B Jul 28 '15 at 15:17
  • @Marc B: Not all stages need the same char set, but the same char set needs to be used on each interface. Java -> PHP may use the same and PHP may convert to the MySQL tables charset and all same back. As long as the character is available in the char sets. – Konrad Jul 28 '15 at 15:35
  • either the same char, or appropriate translation logic at the borders between stages. you can't just blindly stuff text in one charset into a different context and expect it to "just work". – Marc B Jul 28 '15 at 15:36
  • you might want to check this: http://stackoverflow.com/questions/29651301/text-copied-from-jtextarea-have-broken-encoding-after-paste-in-foxpro-applicatio – Garry Jul 28 '15 at 15:40

0 Answers0