[PHP4.1.2] Incorrect browser charset recognition

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CJ Oxx

    [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("defaul t_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.

  • Guest's Avatar

    #2
    [PHP4.1.2] Incorrect browser charset recognition

    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.intern al_encoding
    automatically.


    I don't know how default_charset relates to mb_internal_enc oding("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_ou tput_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é


    Comment

    • CJ Oxx

      #3
      Re: [PHP4.1.2] Incorrect browser charset recognition

      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!


      nospam@nodomain .com wrote:[color=blue]
      > 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.intern al_encoding
      > automatically.
      >
      >
      > I don't know how default_charset relates to mb_internal_enc oding("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_ou tput_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é
      >
      >[/color]

      Comment

      • CJ Oxx

        #4
        Re: [PHP4.1.2] Incorrect browser charset recognition

        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:[color=blue]
        > 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!
        >
        >
        > nospam@nodomain .com wrote:
        >[color=green]
        >> 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.intern al_encoding
        >> automatically.
        >>
        >>
        >> I don't know how default_charset relates to
        >> mb_internal_enc oding("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_ou tput_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é
        >>
        >>[/color]
        >[/color]

        Comment

        • CJ Oxx

          #5
          Re: [PHP4.1.2] Incorrect browser charset recognition

          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.


          nospam@nodomain .com wrote:[color=blue]
          > 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.intern al_encoding
          > automatically.
          >
          >
          > I don't know how default_charset relates to mb_internal_enc oding("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_ou tput_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é
          >
          >[/color]

          Comment

          Working...