开发者

how do i set default char set to null in php

开发者 https://www.devze.com 2023-03-08 22:53 出处:网络
Hi A开发者_StackOverflow中文版ll in phpinfo page I find the charset is UTF-8. Content-Typetext/html; charset=UTF-8

Hi A开发者_StackOverflow中文版ll in phpinfo page I find the charset is UTF-8. Content-Type text/html; charset=UTF-8 I want to remove the charset to null witout changing in php.ini file is it possible.


You can set on top of your file ini_set("default_charset", "");


A "null charset" is the same as ISO-8859-1 according to RFC 2616:

When no explicit charset parameter is provided by the sender, media subtypes of the "text" type are defined to have a default charset value of "ISO-8859-1" when received via HTTP.

Setting the charset to ISO-8859-1 is therefore the same as not setting any charset at all. However, since Google Chrome implements this wrong (they default to UTF-8) you should really consider to explicitly set the charset to ISO-8859-1 (or whichever charset you are using).


If you have the privileges to do so, you can override INI settings on a per-script basis. Otherwise you can simply output an overriding header: header("Content-type: text/html; charset=ISO-8859-1"); or include it directly in your HTML output as <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />, obviously replacing ISO-8859-1 with whatever you want.


You can output a header to set it:

header('Content-type: text/html; charset=YOUR_CHARSET');

If you don't set a charset in this header, the browser will try to guess on its own which is not recommended. Most of the times in western countries that guess would be ISO-8859-1 or ISO-8859-15.


header('Content-Type: text/html'); // note the absence of charset=

Note however, that there's nothing such as "null charset", there's always some kind of mapping between the bytes and characters (even ASCII is such a mapping, not The Natural Order Of Things). What you're doing is telling the browser "I don't know what charset this is, just make a guess" - which may or may not choose the actual charset.

0

精彩评论

暂无评论...
验证码 换一张
取 消