UTF-8 Charset issue - html

I have stored German umlauts like "ßäöü" in my MySQL database which charset is utf-8.
When I get a value like "Straße" from the DB the output is "Stra�e".
When I display this value with utf8_decode(htmlentities()) the output is completely empty " ".
My html header declares already <meta charset="utf-8">.
How can this issue be solved?

Your database is utf-8. Whats your table and column's encoding? Check on that with phpmyadmin. The output of htmlentities is empty because you are not passing an utf-8 string to it, which defaults to an empty string from php 5.4+ (believe me, that compatibility-breaking decision caused many bugs..)

You could try utf8_decode() if you're using PHP, or any similar function in your language.

Related

tinybutstrong not showing special characters from mysql

I'm trying to load data from a MySQL DB from a varchar(35) / utf8_swedish_ci field through TBS (tinybutstrong) and PHP using the example (MySQL data merge). My issue is that data loads fine if only ascii characters are in the fields but as soon as I add a single scandinavian special character like ö or ä the field contents vanishes entirely and other fields in row display correctly.
My understanding is that the latest versions on TBS automatically use UTF-8 coding (I have 3.9.0 for PHP 5) so I assumed it would work out-of-the-box. To be safe, I even added the coding to template as so:
'$TBS->LoadTemplate('mysql.html','UTF-8');' but to no avail.
Could someone please advice what is causing this.
For a good UTF-8 processing, all elements of the chain must be UTF-8.
You have to ensure that your template is UTF-8 : check the entered text and the HTML element <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
You have to ensure that all your PHP scripts are UTF-8 and not Ansi.
You also have to ensure that your MySQL connection is set to receive UTF-8 queries and to return UTF-8 item data. This can be done for example by querying the SQL : SET NAMES 'UTF8'

jsp insert into database no utf-8

I've got web-app (jsp) which is using database (mysql). I've put some data into database to test is it work to show in jsp what's in database There was issue with utf-8 characters (polish letters) but i fixed it by adding <parameter-encoding default-charset="UTF-8" /> into glasfish-web.xml. But i still got problem with putting data into database from form. In database instead of polish character i got "?????". I've tried many thinks and nothing Dont reallu now where to look to fixit
ok problem solved I'll put answer for other people having same problem
In jsp where i start my database connection for url="jdbc:mysql://localhost/databasename i changed it into
url="jdbc:mysql://localhost/databasename?useUnicode=true&characterEncoding=UTF-8"
and now everything in database looks like it shoudl
Problem you have faced is that java has escaped the UTF-8 character sequence.
you can use StringEscapeUtils provided by java in order to escape any characters which become ??? or anything else.
try this :
str = org.apache.commons.lang.StringEscapeUtils.unescapeJava(str);
From java

MySQL European Characters

I can't figure this out for the life of me.
I have a query that pulls translations of elements on a page. So any number of 15 languages can appear on that page. When I start to add languages like Swedish anything that has a symbol such as ö results in the whole field returning a null string.
I've verified the encoding on the table and it claims it's using UTF-8 but seeing as how this doesn't work I'm confused.
Here is the query I'm working with:
SELECT
form.form_id,
elem.elem_type,
elem.elem_name,
elem.elem_format,
elem.elem_required,
trans.trans_label,`
trans.trans_description,
trans.trans_defaultValue,
trans.trans_other,
elem.elem_advancedcommand
FROM
events_form form
LEFT JOIN
events_form_elements elem
ON
form.event_id = elem.event_id
INNER JOIN
events_form_translations trans
ON
elem.elem_id = trans.elem_id
INNER JOIN
events_form_languages lang
ON
trans.lang_id = lang.lang_id
WHERE
form.form_id = '{$formid}' AND lang.language = '{$language}'
ORDER BY
elem.elem_sortorder
Now I tried to do something like:
CONVERT(CAST(trans.trans_description as BINARY) USING latin1) as trans_description,
To force it to covert the encoding but that doesn't yield a result at all.
After I get the result it's immediately json_encoded and returned to the user (Ajax Request). I DON'T think it's the json_encode as doing a print_r of the output array yields the same issues.
Also.. lastly, the system I'm building on is using xPDO so I'm not too sure if that's the issue either.
EDIT:
It seems that PHP IS returning a correct value or at least a value for example here is a print_r dump:
[trans_label] => Ditt f�rnamn?
[trans_description] =>
[trans_defaultValue] => First Name
So it seems that when my json_encode touches that string is when it turns the string to null.
Your PDO connection string should specify the encoding. For example:
mysql:host=localhost;port=3306;dbname=test;charset=utf8
This controls the encoding that the database driver will use when it returns a result, and the encoding the driver assumes your queries are in. If you don't specify it, the default encoding will be used. Often the default is latin1.
You can confirm this by printing the hexadecimal representation of the data with bin2hex in PHP: the ö in förnamn is being returned as f6. If the text was encoded in UTF-8 you would obtain c3b6.
You said nothing about the encoding of your web pages.
Do you have that line in the <head> section of your page to force the encoding to UTF-8?
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
I've had problems endcoding letters to my native language Icelandic but ive found a mutual solution for all utf8 letters.
right after mysql_select_db and before mysql_query insert the following:
mysql_query("SET character_set_connection=utf8,
character_set_results=utf8,
character_set_client=utf8", $con);
Where $con is the connection to mysql
Happy coding..
Your answer is null after conversion due to incompatibility of data types.But showing European or Arabic characters on the page is quite simple.I had the same problem with Arabic language, but after few experiment its works fine now.
If you want to show those European characters on the page (jsp,php,html) first set the page encoding to UTF-8 like: -
pageEncoding="utf-8"
And also you need some changes on your database connection class for utf-8 characters
Use the code below:-
jdbc:mysql:your_ipaddress":3306/"+db+"?requireSSL=false&useUnicode=true&characterEncoding=UTF-8
Hope it will help you.

error while inserting symbol in database with JPA

I am using JPA to insert into Mysql database and it is not able to persist symbols like double quotes(") or euro etc. instead of that it persist Que mark (?)
Looks like some "Unicode problem".
Double check that you are using UTF-8 as character encoding for your tables/database (or maybe even as default CHARACTER SET). See 9.1.3. Specifying Character Sets and Collations.
Thanks for ur reply
It is not Unicode related problem i checked my character set form db to app server
It is UTF-8
if i type the symbol it get inserted into db correctly but if i copied form somewhere else it insert mojibake.

Inserting Chinese Meta Tags

I have a multilingual site and I am having a problem inserting Chinese meta tags. These are transformed into question marks.
Is there a way how I can achieve this?
Many thanks
--EDIT--
The table storing the SEF Urls is in the latin1_swedish_ci character set. How can I change this single table to utf8_general_ci without breaking the URLs?
Many thanks!
Make sure that:
The character encoding you are using includes those characters (UTF-8 is safe)
Your editor is configured to use that character encoding
Your database (if these details are stored in one) is configured to use that encoding
Your webserver is configured to output a charset parameter on the Content-type header (and it uses the correct encoding)
Your browser is not configured to ignore the specified encoding
Use numeric character references.
EDIT
wiki numeric character references
Convert Chinese characters to Unicode
Are you retrieving the data from a database?
If so ensure that you connection character set is also set to utf-8.
In MySQL for example you would need to issue this query before any other:
SET NAMES 'utf8';
It could be that you need to encode the Chinese characters to HTML entities, or specify a character set.
Have you checked your character set in your document headers? I usually use UTF-8 to achieve chinese character sets.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
If you're using a program like dreamweaver, make sure your files are actually being SAVED in the correct character set as well. We had a problem where characters in a dreamweaver file were coming through as ???? because the editor itself was set to iso-8859-1
Maybe your Browser - or more exactly, the font you selected to display the page - doesn't support chinese characters. What system and browser is this on?