views:

484

answers:

4

I have a script that gets a string from the database, splits it into words and writes the words to the database. It works perfectly when i call the script via http (using apache web server). It also works to run it from a windows command line. However, when i try to run it from the command line (shell) in ubuntu all swedish chars ÅÄÖ is replaced with AAO in the database. Very strange.

What is apache telling php that i need to tell it myself when running from command line?

A: 

Probably ubuntu does not accept Terminal that kind of stuff. Try to install a addon or so?

It isnt really strange cause almost all command line stuff have some problems with some special chars. Are you sure you really need that? Is there not an other way to write it? I dont know cause im not swedish.

Apache and PHP just have support for that kind of chars,,, there is nothing to say else

YourComputerHelpZ
I don't input anything from command line, i just execute the script from there. The reason I want it to work from command line is that I want to run it from cron.
Martin
executing and inputting give you (almost) the same output.
YourComputerHelpZ
+2  A: 

MySQL has various parameters dealing with client encoding. Setting the client character set either to UTF-8 or to the database's character set should solve your problem.

Martin v. Löwis
Done that, both are utf8, but it doesn't help.
Martin
+2  A: 

You could put phpinfo() at the top of your script, to print all your environment variables, configuration settings, etc. Compare the output when running at the command line vs running under apache.

Todd Owen
Great tip! There are lots of differences. For example LANG is set to en_US.UTF-8 on command line. From apache it has these:_SERVER["HTTP_ACCEPT_LANGUAGE"] en-US,en;q=0.8_SERVER["HTTP_ACCEPT_CHARSET"] ISO-8859-1,utf-8;q=0.7,*;q=0.3
Martin
A: 

Often there will be a different php.ini file that gets used when run via the command line. Check to see if you have one, and what the differences are.

philfreo