- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
下面是我用于从浏览器创建和下载 CSV 文件的代码片段。
$input_array[] = ['注文日時', '受注番号',];
$input_array[] = ['2015-09-30', 'INV-00001',];
/** open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
/** loop through array */
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($f, $line, ',');
}
/** rewrind the "file" with the csv lines **/
fseek($f, 0);
/** modify header to be downloadable csv file **/
header('Content-Encoding: UTF-8');
header('Content-Type: application/csv; charset=UTF-8');
header('Content-Disposition: attachement; filename="my_csv_file.csv";');
/** Send file to browser for download */
fpassthru($f);
die();
当我打开创建/下载的 CSV 文件时,日语字符变成了奇怪的字符。我的代码片段中有什么不正确的地方?创建 CSV 文件时如何保留日语字符?
最佳答案
如果您想强制任何程序将文件解释为 UTF-8 编码,只需在写入第一行之前直接添加一个带有简单 echo
的字节顺序标记:
$input_array[] = ['注文日時', '受注番号',];
$input_array[] = ['2015-09-30', 'INV-00001',];
echo "\xEF\xBB\xBF";/// Byte Order Mark HERE!!!!
/** open raw memory as file, no need for temp files, be careful not to run out of memory thought */
$f = fopen('php://memory', 'w');
/** loop through array */
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($f, $line, ',');
}
/** rewrind the "file" with the csv lines **/
fseek($f, 0);
/** modify header to be downloadable csv file **/
header('Content-Encoding: UTF-8');
header('Content-Type: application/csv; charset=UTF-8');
header('Content-Disposition: attachement; filename="my_csv_file.csv";');
/** Send file to browser for download */
fpassthru($f);
die();
或者用Excel或者Open Calc导入的时候选择Unicode Character set
,否则直接用notepad/textedit等打开是没有问题的
关于php - 如何使用 PHP 创建保留日文字符的 CSV 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32856716/
我尝试过下面的代码,但只有“?”打印而不是 unicode 字符。 public static void main(String s[]){ char i1 = 0x0ABF; char i2
我有不同语言的字符串,主要是日语,当我尝试将它们打印为字符串时,它们显示得很好。但是,当我将其中许多添加到 python 列表中,然后打印出列表时,它们显示为如下文本:xe9 例如: string1
我目前正在开发一个包含日语和英语字符串的 mysql 数据库。 当前排序规则:utf8_general_ci。 我必须使用 LIKE %'japaneseWordHere'% 查询字符串中的日语单词。
目前,我正在使用这个正则表达式来检测日语标签和英语标签。\B([##][·・ー_0-90-9a-zA-Za-zA-Zぁ-んァ-ン一-龠]{1,24})(?=\W|$)规则是: Hashtag must
这对我来说似乎很难。我有将 CString 打印到文本文件的代码,但该值恰好是 Unicode(日语)。一旦命中此行,它下面的任何内容都不会被打印。 知道如何在文本文件中打印日语文本吗? #defin
我需要知道包含日文/中文字符的 unicode 字符串中有多少个可显示字符。 使问题变得非常明显的示例代码: # -*- coding: UTF-8 -*- str = '\xe7\x9d\xa1\x
请在 IE 中检查以下 js fiddle(我使用的是 10) http://jsfiddle.net/bF65u/1/ .inlineCol2 { width: 50%; } .op
我想向站点发送一个发布请求。下面的 python 代码工作正常。 # -*- encoding=utf-8 -*- import urllib, urllib2 url = "http://xxx.c
这个问题在这里已经有了答案: Unicode string literals in VBA (3 个回答) How to type Unicode currency character in Visu
我正在考虑使用 DejaVu 字体为 CJK 脚本创建 [Ruby-like][1] 字体。 但是我不确定,是否 DejaVu 提供/支持 CJK 字形? 否则,您是否推荐了另一种可重复使用的免费/开
我有一个图像目录,每个图像的名称中都有一个汉字。我正在尝试列出所有图像,在列表上循环,读取并显示每个图像。 图片路径类似于https://github.com/sirius-ai/LPRNet_Pyt
我想在 UITextView 中设置斜体字体样式,但斜体字体在 iOS 7 上不适用于中文/日文/韩文。有人能帮忙吗? 最佳答案 因为iOS上没有斜体中文字体,需要使用affine transform
如果我这样做: import pandas as pd pd.DataFrame( data=nr.random( (2,2) ), columns=[u'é',u'日本'] ).plot() 结果:
我希望能够识别中文、日文和韩文的书面字符,既可以作为一般语言,也可以作为分割语言。这些是原因: 将 CJK 识别为一个通用组:我正在制作一个垂直脚本蒙古语 TextView。为此,我需要将文本行旋转
我正在尝试对我正在处理的几个 URL 中的非 ASCII 字符进行 URL 转义(百分比编码)。我正在使用一个 Flash 应用程序,该应用程序从这些 URL 加载图像和声音剪辑等资源。由于文件名可以
我正在使用 PyPDF2 在 python 中读取 PDF 文件。虽然它适用于英语和欧洲语言(英语字母表),但图书馆无法阅读日语和中文等亚洲语言。我尝试了 encode('utf-8')、decode
我在 VBA 用户窗体中创建了一个 ListView 。 Listview 显示用户在 3 个文本框中插入的数据(单击“保存”按钮后)。用户可以在希伯来语中插入文本,但在 ListView 中,文本显
我有一个由 1 byte slice 假名组成的列表名称(示例 `゙),我通过 2 byte slice 假名 ji 进行搜索,但结果为零。你知道如何将搜索文本从 2 字节的假名转换为 1 字节吗?请
我的 iOS 应用在不同的本地化版本(en_US、en_AU、ja_JP 等)中显示不同的货币(USD、JPY、AUD、EUR) ). 对于日语地区/语言(两者都在我的设备上设置),如果我: NSNu
我们注意到,在 targetSdkVersion 28 期间,EditText 将在输入非英语 unicode(如中文、日语等)后倾向于“稍微下推”该行. 当代码为 targetSdkVersion
我是一名优秀的程序员,十分优秀!