I have been using iconv to convert data from my company's database (windows-1250) to UTF8. It all worked fine until recently.

I'm not really sure what happened, as I've noticed the change only recently. The problem is that iconv seems to stop working well - it still throws notices when I use bad encoding name.

Earlier, when I saved a string to the db with

htmlspecialchars(iconv('UTF-8', 'windows-1250', $string), ENT_QUOTES) it was fine. Now only question marks are written to my db instead of e.g. ąęś.

When I correct them via PL/SQL Developer and read them via php: htmlspecialchars_decode(iconv('windows-1250', 'UTF-8', $string), ENT_QUOTES)

I receive aes. I tried to set the encoding in php, right before string output:

header('Content-Type: text/html; charset=utf-8');, but it didn't help.

My software is:

  • PHP 5.3.15 (cli)
  • iconv (GNU libc) 2.15
  • Apache/2.2.22
  • openSUSE 12.2
  • Oracle 10.2.0.4
  • oci
有帮助吗?

解决方案

After some help from hakre, I was able to solve my problem.

My strings were already transliterated when I selected them from the database. PHP's oci_connect() fourth parameter is character set. If you don't provide it, it is taken from environment variable NLS_LANG.

I had neither fourth parameter nor environment variable, so my database connection charset was wrong. Once I added NLS_LANG variable it started to work fine.

Thank you hakre! : )

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top