How to get utf-8 data using php and show correct encoding in dump excelsheet file?

Hi I am saving mostly English and German characters to the mysql database, which is currently configured for utf-8 encoding.

I assume that I should use the Latin encoding for this data type, is this true?

If so, how can I change the encoding to correct the German characters that are now stored in utf-8?

UPDATE

Maybe this is a return problem ... When I export data from db via php, of course, I return utf-8, can I do a restore to give me latin1?

UPDATE 1

Ok I am creating a website, the html encoding is uft-8, db is uft-8, and now I want to run some export and extract the data that should be returned on the excel sheet, and the data is utf -8, but here I need characters latin1 ... or the encoding of an excel sheet extracted from db should be such that Tรƒยถst displays Tรคst. Right now I get such data โ†’ Tรƒยถst

UPDATE 2

I use the following php script to dump:

http://www.fundisom.com/phparadise/php/databases/mySQL_to_excel

on line 48 I changed the code to

header("Content-Type: application/$file_type; charset=utf-8"); 

no change in behavior.

How can i solve the problem?

Almost a solution

 <?php $text = "รƒยถ is a valid UTF-8 character"; echo 'Original : ', $text, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; ?> 

here is what i need, i think ... but i need to check it in context of php script ... tomorrow :-)

+4
source share
4 answers

I agree with the previous answers that UTF-8 is a good choice for most applications.

Beware of the traps that may be waiting for you! You must be careful to use a constant character encoding on your system (input forms, output web pages, other interfaces that can access or modify data).

I spent several unpleasant hours trying to figure out why a simple? or & eacute; was crippled on my web page, only to find that something was drowning the encoding somewhere. I have even seen cases of text that run through several encoders - turning a single quote into eight bytes once.

On the bottom line, do not assume that the correct translation will be completed; Be explicit about character encoding throughout your project.

Edit: I see that in your update, you have already begun to discover this special joy. :)

0
source

After using double-byte characters like UTF-8, there is no return ...

Closer you can use iconv

like this

 <?php $text = "รผ is still a valid ISO-8859-1"; echo 'Original : ', $text, PHP_EOL; echo 'TRANSLIT : ', iconv("UTF-8", "ISO-8859-1//TRANSLIT", $text), PHP_EOL; echo 'IGNORE : ', iconv("UTF-8", "ISO-8859-1//IGNORE", $text), PHP_EOL; echo 'Plain : ', iconv("UTF-8", "ISO-8859-1", $text), PHP_EOL; ?> 

more details: http://php.net/manual/en/function.iconv.php

+2
source

With UTF-8, you can store any character supported by Unicode. With UTF-8, you can store any character supported by Unicode, so you should have no problem using it to store only Latin characters (which are just actually a small subset of what Unicode supports).

So, you are fine for storing information; if you need to do any conversion while retrieving data, it depends on the connector you use to get the data from the database and how your programming language processes the string.


To update: assuming you are using PHP to create web pages, can you just send the correct HTTP header to indicate that your page is encoded in UTF8?
+1
source

UTF-8 is the best choice for all goals and objectives. If you have no really urgent reason to go to latin1 (for example, compatibility with other applications), go for it.

There are several UTF-8 matches that handle umlauts and sort orders in different ways (see here for a list). You may have to choose one by one depending on your requirements. However, they can all store umlauts.

0
source

Source: https://habr.com/ru/post/1332423/


All Articles