# Default charset

- Thread: https://externals.io/message/21398
- Original archive: https://news-web.php.net/php.internals/21398
- Started by Graziano Liberati on 2006-01-04T09:42:44+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #21398 — Graziano Liberati — 2006-01-04T09:42:44+00:00

URL: https://externals.io/message/21398#21398

Hi, I wrote the same mail some days ago in the general list and I asked also 
on the #php IRC channel on Freenode but I didn't find any answer, so I try 
here.

I need to set the default charset for my application to UTF-8 instead of 
the default one of the webserver that is ISO-8859-1.
I've tried to change the value of default_charset in php.ini and all it's ok, 
but I need to set the value only for one application so I've tried to use the 
ini_set function in this way:
ini_set('default_charset','utf-8');

The problem is that that the ini_set function seems to be ignored, I don't 
have the same effect of changing the php.ini configuration file, with the 
ini_set function the default charset of the output is still ISO-8859-1.

My system: PHP 5.0.5, Apache 2.0.54.

Someone can help me?

Regards.
-- 
Graziano 'FreeJay' Liberati
---------------------------
Main developer of ZNF http://znf.zeronotice.com

Contacts
web: http://www.freejay.it
e-mail: freejay@freejay.it
icq: 98659824
msn: freejay@freejay.it

---

## #21399 — Rasmus Lerdorf — 2006-01-04T10:40:37+00:00

URL: https://externals.io/message/21398#21399 · In reply to: #21398

Not really a question for internals.

   header("Content-type: text/html; charset=UTF-8");

from your application will do the trick.

-Rasmus

Graziano Liberati wrote:
> Hi, I wrote the same mail some days ago in the general list and I asked also 
> on the #php IRC channel on Freenode but I didn't find any answer, so I try 
> here.
> 
> I need to set the default charset for my application to UTF-8 instead of 
> the default one of the webserver that is ISO-8859-1.
> I've tried to change the value of default_charset in php.ini and all it's ok, 
> but I need to set the value only for one application so I've tried to use the 
> ini_set function in this way:
> ini_set('default_charset','utf-8');
> 
> The problem is that that the ini_set function seems to be ignored, I don't 
> have the same effect of changing the php.ini configuration file, with the 
> ini_set function the default charset of the output is still ISO-8859-1.
> 
> My system: PHP 5.0.5, Apache 2.0.54.
> 
> Someone can help me?
> 
> Regards.

---

## #21400 — Uwe Schindler — 2006-01-04T10:45:20+00:00

URL: https://externals.io/message/21398#21400 · In reply to: #21398

Hi Graziano,

At 10:42 04.01.2006, you wrote:
>I need to set the default charset for my application to UTF-8 instead of
>the default one of the webserver that is ISO-8859-1.
>I've tried to change the value of default_charset in php.ini and all it's ok,
>but I need to set the value only for one application so I've tried to use the
>ini_set function in this way:
>ini_set('default_charset','utf-8');
>
>The problem is that that the ini_set function seems to be ignored, I don't
>have the same effect of changing the php.ini configuration file, with the
>ini_set function the default charset of the output is still ISO-8859-1.

create a .htaccess file in the application directory where you use 
the "php_value" command to set this variable. See http://www.php.net/php_value

The problem is that changing the charset in the script is too late 
(it is running so it cannot be changed anymore).

-----
Uwe Schindler
thetaphi@php.net - http://www.php.net
NSAPI SAPI developer
Bremen, Germany

---

## #21401 — Nuno Lopes — 2006-01-04T11:15:43+00:00

URL: https://externals.io/message/21398#21401 · In reply to: #21398

PHP had a bug when handling the default_charset in CGI mode.
Upgrading PHP will do the trick.

Nuno


> Hi, I wrote the same mail some days ago in the general list and I asked 
> also
> on the #php IRC channel on Freenode but I didn't find any answer, so I try
> here.
>
> I need to set the default charset for my application to UTF-8 instead of
> the default one of the webserver that is ISO-8859-1.
> I've tried to change the value of default_charset in php.ini and all it's 
> ok,
> but I need to set the value only for one application so I've tried to use 
> the
> ini_set function in this way:
> ini_set('default_charset','utf-8');
>
> The problem is that that the ini_set function seems to be ignored, I don't
> have the same effect of changing the php.ini configuration file, with the
> ini_set function the default charset of the output is still ISO-8859-1.
>
> My system: PHP 5.0.5, Apache 2.0.54.
>
> Someone can help me?
>
> Regards.

---

## #21406 — Graziano Liberati — 2006-01-04T11:52:19+00:00

URL: https://externals.io/message/21398#21406 · In reply to: #21399

At Wednesday 4 January 2006 11:40, Rasmus Lerdorf you wrote:
> Not really a question for internals.
>
>    header("Content-type: text/html; charset=UTF-8");
>
> from your application will do the trick.
>
> -Rasmus

In this way I set also the text/html content type, but I don't know prior the 
execution if I have an html, pdf or whatever, I want to set only the charset.

Regards.
-- 
Graziano 'FreeJay' Liberati
---------------------------
Main developer of ZNF http://znf.zeronotice.com

Contacts
web: http://www.freejay.it
e-mail: freejay@freejay.it
icq: 98659824
msn: freejay@freejay.it

---

## #21409 — Graziano Liberati — 2006-01-04T12:05:19+00:00

URL: https://externals.io/message/21398#21409 · In reply to: #21400

At Wednesday 4 January 2006 11:45, Uwe Schindler you wrote:
> create a .htaccess file in the application directory where you use
> the "php_value" command to set this variable. See
> http://www.php.net/php_value
>
> The problem is that changing the charset in the script is too late
> (it is running so it cannot be changed anymore).

Why it's too late? The content type (so also the charset) is not setted until 
the first instruction of output, for example I can use (as said by Rasmus)
header("Content-type: text/html; charset=UTF-8");

From the manual:
" Remember that `header()` must be called before any actual output is sent, 
either by normal HTML tags, blank lines in a file, or from PHP. It is a very 
common error to read code with include(), or require(), functions, or another 
file access function, and have spaces or empty lines that are output before 
 `header()` is called. The same problem exists when using a single PHP/HTML 
file."

Regards.
-- 
Graziano 'FreeJay' Liberati
---------------------------
Main developer of ZNF http://znf.zeronotice.com

Contacts
web: http://www.freejay.it
e-mail: freejay@freejay.it
icq: 98659824
msn: freejay@freejay.it
