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

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.

Related

UTF-8 PHP SQL SERVER

I am working using wordpress, php and sql server. On my web page I have a sqlserver query that is not being displayed correctly.
problem
I am not sure of what should I insert on my php or html code to fix this, I have been trying different things but nothing is fixing my problem. I guess it's all about ut8 encoding but I don't know what to do anymore.
This is how I do the query.
$dbh = new PDO ("dblib:host=$hostname:$port;dbname=$dbname","$username","$pw");
$stmt=$dbh->prepare("SELECT TOP 10 till.code......
$stmt->execute();
Try this:
new PDO ("dblib:host=$hostname;dbname=$dbname;charset=utf8","$username","$pw");
Probably it's a problem in HTML generated by Wordpress.
Can you check the meta tags in your HTML?
For HTML4:
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
For HTML5:
<meta charset="UTF-8">
You can find further information on charsets here:
http://www.w3schools.com/html/html_charset.asp
Furthermore it is available in PHP a function able to convert in HTML encoded strings some special characters; you could try to pass columns with problems through the htmlentities function:
http://php.net/manual/en/function.htmlentities.php

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.

Varbinary encoding

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!

Cyrillic - main settings for php, headers and mysql (is UTF8 the solution?)

I have a project where users are supposed to use special characters (cyrillic like 'Врати се на почетак' which means return to top for example). I will have to make some special settings and I need some advice regarding the proper encoding to use for my project:
mysql database - is it good to use this encoding utf8_unicode_ci or should I search to a specific one? (I did not find anything dedicated to cyrillic languages, but this review says it is ok to use this http://forums.mysql.com/read.php?103,187048,188748#msg-188748)
php - will this setting mysql_query("SET NAMES 'utf8'"); be enough in php to parse correctly the mysql query response in my code?
html headers - would this header <META http-equiv="content-type" content="text/html; charset=windows-1251"> suffice for the correct display and interpretation for both browsers and crowlers for my page?
Is there anything else I should be aware of in this issue?
Thank you!
UTF-8 is the better solution for Cyrillic chars in web. But you have to change this:
<META http-equiv="content-type" content="text/html; charset=windows-1251">
to
<META http-equiv="content-type" content="text/html; charset=utf-8">
And of course the source files must be saved with urf-8 enc set.
PS: If you are setting everything in utf8 there is no need of calling mysql_query("SET NAMES 'utf8'"); Its necessary only if you have inherited project with db in other encoding/converting old databases is sometimes nightmare/

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

Categories