By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,920 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,920 IT Pros & Developers. It's quick & easy.

Language settings?

100+
P: 310
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:

Expand|Select|Wrap|Line Numbers
  1. echo "Danish letters: , , <br>";
  2.  
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
May 9 '08 #1
Share this Question
Share on Google+
9 Replies


Atli
Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  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>
  10.  
May 12 '08 #2

100+
P: 310
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:

Expand|Select|Wrap|Line Numbers
  1. echo "Danish letters: <br>";
  2.  
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!
May 13 '08 #3

hsriat
Expert 100+
P: 1,654
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.
May 13 '08 #4

100+
P: 310
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.
May 13 '08 #5

hsriat
Expert 100+
P: 1,654
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.
May 13 '08 #6

100+
P: 310
Yes, I did try that but it did not help.

A real mystery :-)
May 13 '08 #7

100+
P: 310
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.
May 14 '08 #8

Atli
Expert 5K+
P: 5,058
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
May 14 '08 #9

100+
P: 310
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.
May 15 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.