471,320 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,320 software developers and data experts.

[PHP4.1.2] Incorrect browser charset recognition

I have a problem with browser charset recognition when using PHP 4.1.2
(this is the PHP version which our hosting company provides).

For charset recognition, I use the following meta-tag:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Here is what I have tried so far:
- Regular html page: charset is properly recognised
- PHP page which just prints out the html: charset is not properly
recognised (ISO charset is chosen instead)
- ini_set("default_charset", "utf-8"): php_info() indicates that the
default charset has been set to utf-8, but still the regular ISO charset
is being used when the page is being displayed.
- Parsing the PHP page on my local PHP server (which is running 4.2.3):
Charset is properly recognised

The strange thing however is that it did work properly initially, but
about a month ago the problems with charset recognition started. The
PHP version of the provider has stayed the same, but maybe they have
changed some php settings (this is not very likely however).

Anyone has some advice for me?

Thanks in advance,
cj.

Jul 16 '05 #1
4 6023
I had to write XML with the UTF-8 characterset for interaction with a Flash
movie. To accomplish this I had to ask my hosting provider to activate the
mbstring functions in PHP. Would be worth to compare your local and remote
server on this point. In the PHP manual it says:

--enable-mbstring : Enable mbstring functions. This option is required to
use mbstring functions.
--enable-mbstr-enc-trans : Enable HTTP input character encoding conversion
using mbstring conversion engine. If this feature is enabled, HTTP input
character encoding may be converted to mbstring.internal_encoding
automatically.
I don't know how default_charset relates to mb_internal_encoding("UTF-8");
May be you will need that as well.

When your internal encoding is different, like it was in my case (all my
data was in another character set), you will need:

mb_http_output("UTF-8");
ob_start("mb_output_handler");

This will output UTF-8 character set while input and internally works with
another character set.

All this won't work when the mbstring functions are not activated before.

I hope this has helped you somehow.

René
Jul 16 '05 #2
Both the hosting and my local server do not have the mbstring functions
enabled, so I doubt that my problems are related to this. What happens
is that the browser just does not set encoding to "UTF-8". I requested
two documents, one called test.htm and the other one test.php. They
both contained the same html text (no php scripting): just a meta tag
which sets the content type to "UTF-8". The document with the html
extension worked flawlessly, the php document did not. I find this
particularly strange.

Anyway, big thanks for trying to help me, it is very much appreciated!
no****@nodomain.com wrote:
I had to write XML with the UTF-8 characterset for interaction with a Flash
movie. To accomplish this I had to ask my hosting provider to activate the
mbstring functions in PHP. Would be worth to compare your local and remote
server on this point. In the PHP manual it says:

--enable-mbstring : Enable mbstring functions. This option is required to
use mbstring functions.
--enable-mbstr-enc-trans : Enable HTTP input character encoding conversion
using mbstring conversion engine. If this feature is enabled, HTTP input
character encoding may be converted to mbstring.internal_encoding
automatically.
I don't know how default_charset relates to mb_internal_encoding("UTF-8");
May be you will need that as well.

When your internal encoding is different, like it was in my case (all my
data was in another character set), you will need:

mb_http_output("UTF-8");
ob_start("mb_output_handler");

This will output UTF-8 character set while input and internally works with
another character set.

All this won't work when the mbstring functions are not activated before.

I hope this has helped you somehow.

René


Jul 16 '05 #3
Hmmm, if I save my document as UTF-8 (instead of ASCII), the browser
sets the Charset to UTF-8 but I cannot use sessions anymore since the
header has already been sent (apparently PHP does not ignore the UTF-8 BOM).

Anyone knows a work-around? I just need to be able to set the browser
to UTF-8, the PHP file can be in ASCII, no problem. But whenever the
PHP parser is used, the html meta tag just seems to be ignored.

Maybe the mbstring functions can indeed offer a solution, although I do
not have them enabled on my home 4.2.3 server where everything works fine.
CJ Oxx wrote:
Both the hosting and my local server do not have the mbstring functions
enabled, so I doubt that my problems are related to this. What happens
is that the browser just does not set encoding to "UTF-8". I requested
two documents, one called test.htm and the other one test.php. They
both contained the same html text (no php scripting): just a meta tag
which sets the content type to "UTF-8". The document with the html
extension worked flawlessly, the php document did not. I find this
particularly strange.

Anyway, big thanks for trying to help me, it is very much appreciated!
no****@nodomain.com wrote:
I had to write XML with the UTF-8 characterset for interaction with a
Flash
movie. To accomplish this I had to ask my hosting provider to activate
the
mbstring functions in PHP. Would be worth to compare your local and
remote
server on this point. In the PHP manual it says:

--enable-mbstring : Enable mbstring functions. This option is required to
use mbstring functions.
--enable-mbstr-enc-trans : Enable HTTP input character encoding
conversion
using mbstring conversion engine. If this feature is enabled, HTTP input
character encoding may be converted to mbstring.internal_encoding
automatically.
I don't know how default_charset relates to
mb_internal_encoding("UTF-8");
May be you will need that as well.

When your internal encoding is different, like it was in my case (all my
data was in another character set), you will need:

mb_http_output("UTF-8");
ob_start("mb_output_handler");

This will output UTF-8 character set while input and internally works
with
another character set.

All this won't work when the mbstring functions are not activated before.

I hope this has helped you somehow.

René


Jul 16 '05 #4
Hello René,

I did some more testing and the mbstring seem to be able to provide a
solution :) On my test server, the UTF meta tag works, but when I set
the meta tag to ISO, enable the mbstring functions and use
mb_http_output("UTF-8"), the browser detects UTF-8 and ignores the meta
tag settings. So this is great news! I have contacted the provider and
requested to enable the mbstring functions.

Thank you very much for your help,
cj.
no****@nodomain.com wrote:
I had to write XML with the UTF-8 characterset for interaction with a Flash
movie. To accomplish this I had to ask my hosting provider to activate the
mbstring functions in PHP. Would be worth to compare your local and remote
server on this point. In the PHP manual it says:

--enable-mbstring : Enable mbstring functions. This option is required to
use mbstring functions.
--enable-mbstr-enc-trans : Enable HTTP input character encoding conversion
using mbstring conversion engine. If this feature is enabled, HTTP input
character encoding may be converted to mbstring.internal_encoding
automatically.
I don't know how default_charset relates to mb_internal_encoding("UTF-8");
May be you will need that as well.

When your internal encoding is different, like it was in my case (all my
data was in another character set), you will need:

mb_http_output("UTF-8");
ob_start("mb_output_handler");

This will output UTF-8 character set while input and internally works with
another character set.

All this won't work when the mbstring functions are not activated before.

I hope this has helped you somehow.

René


Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by darren.brierton | last post: by
reply views Thread by Oleg Medyanik | last post: by
6 posts views Thread by Dario Di Bella | last post: by
reply views Thread by FrankL | last post: by
1 post views Thread by news8080 | last post: by
6 posts views Thread by Leon_Amirreza | last post: by
14 posts views Thread by Jeff | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.