4

I am trying to use iconv to remove accents from names using this function

$name = iconv('UTF-8', 'ASCII//TRANSLIT', $original)

So if $original was 'šñć' I would expect 'snc'.

Running this via a PHP script in the command line does produce the expected result, however running the same function in a Symfony 2 application in an Apache web server (on the same machine) removes all accented characters from the output string - so that 'Bijelić' becomes 'Bijeli'

What factors could be a effect this and how could I get the result I want calling this function in Symfony? Thanks!

bScutt
  • 872
  • 8
  • 23
  • Maybe it helps if you print the phpinfo()'s output's iconv section in both of enviroments and compare them. – Lajos Veres Apr 16 '14 at 10:00
  • possible duplicate of [How do I remove accents from characters in a PHP string?](http://stackoverflow.com/questions/1017599/how-do-i-remove-accents-from-characters-in-a-php-string) – Alexey B. Apr 16 '14 at 10:03
  • Check if the local is different in apache and in cli. When using iconv, locale must be set. – 1ed Apr 16 '14 at 10:04
  • @forgottenbas - I did look at that question, however I do get the correct result using the CLI, so I don't think it is an issue with the version of iconv, though I could be wrong. – bScutt Apr 16 '14 at 10:05
  • @1ed - the locale has beens et as follows in both cases ```intl.default_locale = en``` – bScutt Apr 16 '14 at 10:17

2 Answers2

1

So it does turn out that the Locale was not set the same for Apache and the CLI.

Calling setlocale(LC_CTYPE, "en_US.utf8"); before calling iconv produces the expected result.

How does one set the LC_CTYPE in either PHP or Apache?

bScutt
  • 872
  • 8
  • 23
1

I had the same problem. I found that locale was changing by /etc/apache2/envvars

gadelat
  • 1,390
  • 1
  • 17
  • 25