Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Language settings?

Question posted by: coolsti (Familiar Sight) on May 9th, 2008 08:39 AM
This may not be a PHP problem, but at the moment I do not know where the solution is. So assuming it may have to do with PHP, I will post this here. If anyone knows that the solution to this problem should be found elsewhere, please let me know!

I am setting up a new Linux server (Novel Suse 10.1) to run my PHP/MySQL database applications. I am located in Denmark. On my other Linux machines, I can get the special Danish letters å, ø, æ to be correctly displayed on the user's browser simply by echo'ing them to the browser without needing to use any special HTML character coding, for example:

Code: ( text )
  1. echo "Danish letters: å, æ, ø<br>";


But this does not work on the new SUSE machine, I get strange symbols instead. I do get the correct Danish letters when typing them in a terminal window, and when I put the above echo statement in a PHP script and use the CLI version of php5 to run the script directly from the terminal with output to the terminal. So the Danish alphabet is somehow installed on the SUSE machine. It is just not sent out correctly from PHP scripts when they are run from Apache and the output is sent to a remote browser. Again: these are the very same scripts that run correctly on my other machines.

Does anyone know what I need to do to get the proper language alphabet settings to work? Is this a PHP configuration? Or must I look elsewhere?

Thanks!

Steve, Denmark
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Atli's Avatar
Atli
Moderator
1,916 Posts
May 12th, 2008
01:25 AM
#2

Re: Language settings?
I would guess this has something to do with which charset the browser is being told to use.
What charset are the pages on your other servers using?

What happens if you print the letters in proper HTML markup, specifying the correct charset?
Like:
Code: ( text )
  1. <html>
  2. <head>
  3.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. </head>
  5.  
  6. <body>
  7. <?php echo "Danish letters: å, æ, ø<br>"; ?>
  8. </body>
  9. </html>

Reply
coolsti's Avatar
coolsti
Familiar Sight
166 Posts
May 13th, 2008
07:48 AM
#3

Re: Language settings?
Thanks for the reply.

This is a mystery to me.

I did some more experimenting.

1) Danish letters appear on the user's browser correctly when they are read from the database to a PHP variable and then echo'ed to the user's browser.

2) Danish letters do not appear correctly when they are "hard coded" in the PHP script, for example using a statement like this:

Code: ( text )
  1. echo "Danish letters: åøæ<br>";

3) Danish letters appear correctly in a shell terminal window, and they appear correctly in the VIM editor which I am using.


I still do not count out the possibility that this is somehow a PHP configuration issue. But it also may be an Operating system configuration issue.

By the way, adding the meta line to the html as Atli suggests did not help.

Can anyone help here?

Thanks!

Reply
hsriat's Avatar
hsriat
Expert
1,427 Posts
May 13th, 2008
09:22 AM
#4

Re: Language settings?
Apparently there's a problem with the editor you are using.

Replace the Danish characters (hard coded ones) with the respective Unicode. This may help.

Find the Unicode table here.

Reply
coolsti's Avatar
coolsti
Familiar Sight
166 Posts
May 13th, 2008
10:25 AM
#5

Re: Language settings?
Ok, that helps a bit, if I could find out that it is the editor that is causing the problem.

But is it? Consider this experiment:

I have a Centos 4.5 PC where everything works correctly. I create a PHP script on this machine which prints out some Danish letters as part of an html page in an echo statement. This works correctly on the Centos 4.5 PC.

I then copy this script file (using scp) to the SUSE 10.1 PC. And without ever opening the file with any editor on the SUSE 10.1 PC, I call the script, and the Danish letters appear incorrectly.

I did not use an editor on the SUSE machine for this file, so I cannot have "corrupted" the letters because of the editor. And since the file prints correctly when called from the Centos PC where the file was created, I would assume that the editor on the Centos PC is correct.

So still a mystery to me. It seems like a missing configuration somewhere on the SUSE machine. But maybe not with PHP.

Reply
hsriat's Avatar
hsriat
Expert
1,427 Posts
May 13th, 2008
10:52 AM
#6

Re: Language settings?
That is weird.

Do one thing, add the php header for encoding type. May be the default settings in your server are not set for UTF-8 but ISO-8859-1.

Reply
coolsti's Avatar
coolsti
Familiar Sight
166 Posts
May 13th, 2008
12:44 PM
#7

Re: Language settings?
Yes, I did try that but it did not help.

A real mystery :-)

Reply
coolsti's Avatar
coolsti
Familiar Sight
166 Posts
May 14th, 2008
07:11 AM
#8

Re: Language settings?
Well I did solve the problem by adding the meta tag to the header section. I had tried this yesterday but it did not help then, so I must have introduced a syntax error in my haste. I tried again and it works now.

Still a mystery why this is needed for the one machine and not the other. Maybe an Apache configuration issue. But it does not seem to be related to PHP at all.

Reply
Atli's Avatar
Atli
Moderator
1,916 Posts
May 14th, 2008
09:42 PM
#9

Re: Language settings?
Quote:
Originally Posted by coolsti
Still a mystery why this is needed for the one machine and not the other. Maybe an Apache configuration issue. But it does not seem to be related to PHP at all.

Take a look at the AddDefaultCharset Directive.

It attempts to force the given charset on all pages sent as text/plain or text/html.
Maybe this is set on your other servers?

Personally, I would prefer to leave this off and specify it for each page, but thats just me :P

Reply
coolsti's Avatar
coolsti
Familiar Sight
166 Posts
May 15th, 2008
06:23 AM
#10

Re: Language settings?
Hi Atli,

it would also be just me as well :)

I am adding the meta tag to the PHP scripts that produce my page headers. Fortunately I have programmed everything in a very simple OOP manner (where I have a class that produces the main page structure including header), so there is only one place in one file per application that I need to make this addition :)

But thanks for the tip. May be interesting to dig a bit and see if what you are saying is the case.

Reply
Reply
Not the answer you were looking for? Post your question . . .
174,847 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top PHP Forum Contributors