如果第一个字母带有重音符号,则会消失(CSV 文件,UTF-8 编码)
我实际上正在开发一个使用 zend 框架用 php 编码的 Web 应用程序。我需要用法语和英语翻译每一页,所以我使用 csv 文件来完成它。
我的问题是,当一个单词以 É 或 À 等重音字母开头时,该字母就会消失,但会显示该单词的其余部分。
例如,如果我的 csv 文件包含 Écriture
,它会显示 criture
。但如果我有 execution
,它会毫无问题地显示 execution
。
每次我想在视图中显示文本时,我只需调用 translate('line to call in csv'); ?>
并显示我的文本。
就像我说的,我的应用程序是用 UTF-8 编码的,并且我对特殊字符没有任何问题,除非它们是第一个。我用谷歌搜索但暂时找不到任何东西。
已经感谢您的帮助!
更新
我忘了说,当我在 zend browser 中执行我的应用程序来调试它时,一切都很好,我的 É 显示出来。只有在 IE 或 FF 等浏览器中我才会遇到问题。
更新 #2
我刚刚发现另一篇讨论 fgetcsv 的帖子,看起来我用来翻译 csv 文件的函数正在使用 fgetcsv() ...这可能是问题所在吗?如果是的话,我该如何修复它?它的编码方式与 Zend Translate 库中的编码方式相同,我不确定是否要开始更改其中的内容...
更新 #3
我继续研究,发现 PHP 在使用 UTF-8 编码时存在问题。但 Zend Framework 默认编码为 UTF-8,所以我确信有一种方法可以完成这项工作。我仍在搜索,但我希望有人能找到解决方案!
I'm actually working on a web application coded in php with zend framework. I need to translate every pages in french and english so I use csv file to do it.
My problem is when a word start with an accentued letter like É or À, the letter just disappear, but the rest of the word is displayed.
For example, if my csv file contains Écriture
, it displays criture
. But if I have exécution
, it displays exécution
without any problems.
Everytime I want to display text in my view, I just call <?php echo $this->translate('line to call in csv'); ?>
and my text is displayed.
Like I said ,my application is encoded with UTF-8, and I don't have any problems withs specials characters, except when they're first. I googled it but couldn't find anything for now.
Thanks already for your help !
UPDATE
I forgot to say that when I execute my application in zend browser to debug it, everything's fine, my É displays. It's only in broswers like IE or FF that I have the problem.
UPDATE #2
I just found another post talking about fgetcsv, and it looks like the function I use to translate from my csv file is using fgetcsv() ... could it be the problem ? And if it is, how can I fix it ? It's coded like that in Zend Translate library I'm not sure I want to start changing things there ...
UPDATE #3
I continued my research and I found issues in PHP when encoded UTF-8. But Zend Framework is encoded UTF-8 by default so I'm sure there is a way to make this work.. I'm still searching but I hope someone has the solution !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题,我尝试了 AJ 的解决方案,它有效:
缺少 csv 中字段的第一个字符
问题似乎是 fgetcsv () 使用区域设置,只需使用
I had the same problem, I tried AJ's solution and it worked:
Missing first character of fields in csv
The problem seems to be that fgetcsv() uses locale settings, just use
"key1";"value1" ##
第一行
"key1";"value1" ##
第二行
"key1";"value1" ##
第一行
这对我来说就像 ussue 一样解决
"key1";"value1" ##
first line
"key1";"value1" ##
second line
"key1";"value1" ##
fird line
this solve like ussue for me
使用十六进制编辑器查看 csv 文件并确保它以正确的方式编码
“É”为
0xC3 0x89
,“À”是
0xC3 0x80
view csv file using hex editor and make sure it is encoded in the right way
"É" is
0xC3 0x89
,"À" is
0xC3 0x80
您的代码中是否有一些
strtoupper()
或ucfirst()
或类似函数?在这种情况下,请尝试mb_strtoupper($str, 'UTF-8')
Did you have some
strtoupper()
orucfirst()
or similar functions in your code? In that case trymb_strtoupper($str, 'UTF-8')