My old server is working perfectly with special character but when I moved whole source code on Amazon instance whole site look weird because of special character.
Below are configuration on newly created instance on Amazon
PHP Version : PHP Version 5.3.29-Ubuntu/trusty/Sergey/r10 (amazon instance)
PHP Version 5.3.3-7+squeeze19 (old server)
Mysql Version : 5.5.46 (amazon instance)
5.1.73 (old server)
Data base collation : "utf8_general_ci"
Tables Collation : "utf8_general_ci"
Fields Collation : "utf8_general_ci"
Set Content Type in php style as well as html style under <head> tag
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
header ('Content-type: text/html; charset=utf-8');
But still special character issue can not be resolved still content display like
Fetch from database and display in PHP page it won't display in correct format
"Tablet Caf� in Bibliotheek Ommen"
And when I try to put static string in PHP page it displays correct format.
"Tablet Café in Bibliotheek Ommen"
Also to make a href link I have created custom function to replace special character with "_" so the URL will not break.
$special_character = array(" ","<",">","#","%",",","{","}","|","\\","^","~","[","]","`",";","/","?",":","#","=","&","$",",","(",")",",","'",".","ë","À","Á","Â","Ã","Ä","Å","Æ","Ç","Ð","È","É","Ê","Ë","Ì","Í","Î","Ï","Ñ","Œ","Ò","Ó","Ô","Õ","Ö","Ø","ß","Š","Ù","Ú","Û","Ü","Ý","Ÿ","à","á","â","ã","ä","å","æ","ç","¢","è","é","ê","ë","ì","í","î","ï","ñ","œ","ò","ó","ô","õ","ö","ø","ð","š","ù","ú","û","ü","ý","ÿ","€","ƒ","£","¥","…","ª","º","¹","²","³","¼","½","¾","¿","ˆ","‹","›","¦","«","»","×","©","™","®","±","÷","µ","¶","¤","°","‰","§","·","¬","•","¡","†","‡","!");
and then using str_replace my script will replace all special character (which are in above array) with "_"
str_replace($special_character,"_",strip_tags($fetch_art[$i]['title']))
So now my URL is "www.xyz.com/news/Tablet_Caf�_in_Bibliotheek_Ommen".
(in my old server is working fine)
But when I use utf8_encode it works fine. I don't want to use with utf8_encode so Kindly suggest alternate way to display special character.
Does the Amazon server need any other configuration?
The black diamond (�) is the browser's way of saying it does not know how to display a particular character. It comes from having latin1 characters, but telling the browser to display utf8 characters.
So check:
the bytes in your client are utf8
you are connecting with utf8 set_charset('utf8') or SET NAMES utf8
the table/column says CHARACTER SET utf8
the meta tag in the header of the html says UTF-8.
(Do not use utf8_encode or any other transformation functions.)
Because my database is about postage stamps there are a lot of half symbols in the descriptions. They type into mysql with no problem but when I get the results of a query all the half symbols have been replaced by a question mark.
Is there a special code I should be using when I input the descriptions instead of using the half symbol? Otherwise, is there another solution like changing the character set. I'm using utf-8 at the moment.
It seems like you are facing character encoding issue. You should use UTF-8 everywhere:
Make sure the column that contains text data is encoded as utf8_...
Check that when you get information from database, you keep this encoding. You can force it by sending SET NAMES utf8; before any request to MySQL.
Check that when you display this information the encoding is UTF-8 (in a webpage, that means <meta charset='utf-8'> in <head>).
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.
I have a problem with MySQL and charsets .
When I insert something into my mysql database, the special chars like "é" change into "è" and some other strange character combinations...
Searching on the web, I read about set utf8_unicode_ci tables and general configuration. I also added the following line to my webpage
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
But after all this it always returns the same error when I insert something into the database. The characters are still garbled.
What do I miss?
You might want to add this to your code:
mysql_query("SET CHARACTER SET utf8");
It will tell PHP to use Unicode to talk with the database engine. So if your form data encoding is unicode too, you shouldn't have any garbled characters problems anymore.
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?