如何使用php检索utf-8数据,并在excelsheet db dump中显示正确的编码? [英] How to retrieve utf-8 data with php and show the correct encoding in an excelsheet db dump?

查看:129
本文介绍了如何使用php检索utf-8数据,并在excelsheet db dump中显示正确的编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我假设我应该使用latin1字符集对于这种类型的数据,是正确的吗?



如果是这样,我该如何更改字符集纠正德语字符现在保存在utf-8?



UPDATE



也许这是一个检索问题...当我导出数据db通过php当然我得到utf-8回来,我可以retrival给我latin1吗?



UPDATE 1 >

Ok我正在建立一个网站,html编码是uft-8,db是uft-8,现在我想运行一些导出和提取数据,一个excel表,数据是utf-8,但在这里我需要的字符是latin1 ...或从数据库提取的excel表格的编码需要是这样的TÃ将显示Täst。现在我得到这样的数据 - >Töst



UPDATE 2



我使用下面的php脚本做转储:



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



在第48行我已更改代码

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

行为无变化。



我会解决这个问题吗?



几乎解决方案

 <?php 
$ text =¶是有效的UTF-8字符;
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;
?>

这是我需要我想...但我需要检查它的上下文php脚本...明天: - )

解决方案

我同意前面的答案,UTF-8是大多数应用程序的不错选择



请注意可能正在等待你的陷阱!您需要小心,在整个系统中使用一致的字符编码(输入表单,输出网页,其他前端可能访问或更改数据)。



<我花了一些不愉快的时间试图找出为什么一个简单的β或é在我的网页上被修改,只是发现某处的东西已经编码了一个编码。我甚至看过一些通过多个编码器运行的文本 - 一次将一个单引号转换为八个字节。



底线,不要假设正确翻译将完成;



编辑:我看到在您的更新中,您已经开始发现这个特别的喜悦。 :)


Hi I am saving mostly english and german characters into a mysql database which currently is set to utf-8 charset.

I am assuming that I should use latin1 charset for this type of data, is that correct?

If so how can I change the charset to correct the german chars which are now saved in utf-8?

UPDATE

Maybe then it is a retrival problem ... When I export data from the db via php of course I get utf-8 back, can I do the retrival to give me latin1?

UPDATE 1

Ok I am building a website, the html encoding is uft-8 the db is uft-8, and now I want to run some exports and extract data, which should be returned in an excel sheet, and the data is utf-8, but here I need the chars to be latin1 ... or the encoding of the excel sheet extracted from the db need to be such that Töst will show Täst. Right now I get the data like this -> Töst

UPDATE 2

I am using following php script to do the dump:

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

on line 48 I have changed the code to

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

no change in behaviour.

How would I solve the issue?

Almost 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;
?>

this is what I need I think ... but I need to check it in context of the php script... tomorrow :-)

解决方案

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

Beware the traps that might be awaiting you, though! You'll want to be careful that you use a consistent character encoding throughout your system (input forms, output web pages, other front ends that might access or change the data).

I have spent some unpleasant hours trying to figure out why a simple β or é was mangled on my web page, only to find that something somewhere had goofed up an encoding. I've even seen cases of text that gets run through multiple encoders--once turning a single quotation mark into eight bytes.

Bottom line, don't assume the correct translation will be done; be explicit about character encoding throughout your project.

Edit: I see in your update you've already started to discover this particular joy. :)

这篇关于如何使用php检索utf-8数据,并在excelsheet db dump中显示正确的编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆