如果第一个字母带有重音符号,则会消失(CSV 文件,UTF-8 编码)

发布于 2024-12-10 10:04:54 字数 910 浏览 0 评论 0原文

我实际上正在开发一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾其所爱 2024-12-17 10:04:54

我遇到了同样的问题,我尝试了 AJ 的解决方案,它有效:
缺少 csv 中字段的第一个字符

问题似乎是 fgetcsv () 使用区域设置,只需使用

setlocale(LC_ALL, 'en_US.UTF-8');

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

setlocale(LC_ALL, 'en_US.UTF-8');
心意如水 2024-12-17 10:04:54
In .csv file content try to use
; as delimiter 
  and 
" as enclosure.
something like this inside .csv file

"key1";"value1" ##第一行

"key1";"value1" ##第二行

"key1";"value1" ##第一行

这对我来说就像 ussue 一样解决

In .csv file content try to use
; as delimiter 
  and 
" as enclosure.
something like this inside .csv file

"key1";"value1" ##first line

"key1";"value1" ##second line

"key1";"value1" ##fird line

this solve like ussue for me

望笑 2024-12-17 10:04:54

使用十六进制编辑器查看 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

幻梦 2024-12-17 10:04:54

您的代码中是否有一些 strtoupper()ucfirst() 或类似函数?在这种情况下,请尝试 mb_strtoupper($str, 'UTF-8')

Did you have some strtoupper() or ucfirst() or similar functions in your code? In that case try mb_strtoupper($str, 'UTF-8')

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文