Varbinary encoding - php

I got a varbinary field in my database, and got some problems with displaying special (Polish) characters like ąśćężźć.
Example: SELECT local_name from items WHERE id = 140 returns: Pieczęć, the problem appears when I want to print this data on my website (encoding UTF-8 there), then the Pieczęć turns into the following string: Piecz�� tried also to use utf8_encode() PHP function but it gives the following result: Pieczêæ.
How can I solve that so it will print the special characters without problem?

same adivce as here:
https://stackoverflow.com/a/11254131/1489924
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" >
and/or
SET NAMES 'utf8'
worked for me in most situations.
Good luck!

Related

How to retrive UTF-8 Data from MSSQL via PHP to HTML

how can i get the UTF-8 data from the MSSQL Table. I have some names that are wrong converted. In the place where the umlat mark is I'm getting a sign like this �.
So for a name Gergö it show's Gerg�.
I'm not sure where the problem is. From the MSSQL to PHP conversion or PHP to HTML conversion. For this purpose im using the sqlsrv functions.
In HTML i added the meta tag <meta http-equiv="content-type" content="text/html; charset=UTF-8"> but this didn't solve the problem. I also added before the connection starts the ini_set('mssql.charset', 'UTF-8'); function but this also didn't helped.

Encoding error causes MS SpecialChars to be shown as question marks

So when I retrieve a column from my database and echo the string in php it displays microsoft special chars as this �.
However if I copy the string from the cell, paste it into my script and echo it directly, I get the correct content.
At what stage between retrieving the data and displaying it is this going wrong?
It is an MS SQL database. If any more information on current set up will help, let me know and I will supply it, it's just at this point I'm not sure what will be usefull and what wont.
It's down to encoding.
Is your database table encoded in the same character set as the PHP document, e.g. UTF=8?
If you can, either change the database table's collation or the PHP document's encoding, either with
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
or
header('Content-Type: text/html; charset=utf-8');
with the correct character set.

words with accents appear with strange chars in mysql

Information that I send to mysql with accents are appearing with strange chars, for example správce is admin in my language. And when I send this to mysql it appears like "správce".
Im trying to find information to solve this problem, and I saw two solutions, but any is working.
1st solution with meta tags, dont works:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
2º solution with htmlspecialchars method also dont works
if($f['level_admin'] == '1') { $f['level_admin'] = htmlspecialchars('Správce', ENT_QUOTES, "UTF-8"); }
if($f['level_admin'] == '2') { $f['level_admin'] = htmlspecialchars('Super Správce', ENT_QUOTES, "UTF-8");}
Do you know some way that work effectively?
It's also important to know what collation is set in the MySQL DB Table - dependent on your needs you could use for example "utf8_unicode_ci" .
There is also a php function that converts string to UTF8
utf8_decode()
utf8_encode()
Normally this helps - but you better check the collation in the DB.

Character set encoding issue

All, Im having the age old problem with character encoding...
I have a mySQL DB with a field set to utf8_unicode_ci. My PHP page as the header entry <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />. When I use a simple form to POST data with Cyrillic characters to the DB, e.g. 'гыдлпоо', the characters display correctly in the textarea, and are added to the DB where they display correctly.
When fetching the characters from the DB, my page only displays a series of question marks. I've used mb_detect_encoding($content, "UTF-8,ISO-8859-1", true); and the content is UTF-8, however the characters do not display.
I've searched around (including on SO) and tried any number of solutions, to no avail- any help would be much appreciated.
Many thanks
Do this right after mysql_connect() and mysql_select_db():
mysql_query("SET NAMES 'utf8'");
Try using mysql_set_charset() function before fetching data from database.
did you try to use the form with
enctype="multipart/form-data"
?
this might help.. it's not necessary for the text to be readable in your database.. when they are saved they should be utf8 encoded.. you need them to look fine when you output the string again

Change the characters in mysql with Convert failing - Still getting Não

I am populating this mysql table with data from a php (via post and using filter_input).
The database is utf8 but when I have a user that inputs words with ^,',',~ like Não I get this -> Não
What do I have to do to make it show the correct values. Or should I try to make some correction when I retrieve the data??
UPDATE:
I have added a utf8_decode and now it is inserting ok.
Anyone know how to convert the string that were already in the table?? I tried using the convert function but I can't make it work :(
UPDATE:
I am trying this code:
select convert(field using latin1)
from table where id = 35;
And I am still getting this: Não
I tried other encoding s but I never get the word Não
Anyone have any thoughts on this one??
First, make sure your page is utf-8
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
next, if your on Apache, make sur your in UTF-8 in config file :
AddDefaultCharset UTF-8
or your can do it in a .php file like this :
header('Content-type: text/html; charset=UTF-8');
if you still have problem, you can use the encode function :
$value = utf8_encode($value);
Hope all this will help...
It looks like somewhere along the way something cannot handle Unicode. As a result, ã is getting interpreted as two separate characters. Make sure everything that handles strings is OK with Unicode.

Categories