gpt4 book ai didi

php - 更改 PHP 函数的默认字符集,如 "htmlspecialchars"

转载 作者:可可西里 更新时间:2023-11-01 12:56:19 25 4
gpt4 key购买 nike

我使用的是 PHP 5.2.6,我的应用程序的字符集是 UTF-8。

现在,我应该如何更改 PHP 的默认字符集?不是指定输出的 MIME 时间和字符集的那个。

但是对于所有 PHP 函数,如 htmlspecialchars、htmlentities 等,这将发生变化。

我知道,那些函数中有一个参数接受输入字符串的字符集。但我不想为我使用的所有功能指定。如果我忘记了某个地方,那将是一团糟。

我也知道,我可以包装这些函数并创建我自己的包装器,例如:

function myHtmlize($str)
{
return htmlspecialchars($str, ENT_COMPAT, 'UTF-8');
}

我也不喜欢这个解决方案。

我真的很想告诉 PHP,默认情况下以 'UTF-8' 作为字符集。不是“iso-8859-1”。

这可能吗?

最佳答案

喜欢这个吗? http://us2.php.net/manual/en/function.setlocale.php

* LC_ALL for all of the below
* LC_COLLATE for string comparison, see strcoll()
* LC_CTYPE for character classification and conversion, for example strtoupper()
* LC_MONETARY for localeconv()
* LC_NUMERIC for decimal separator (See also localeconv())
* LC_TIME for date and time formatting with strftime()
* LC_MESSAGES for system responses (available if PHP was compiled with libintl)

关于php - 更改 PHP 函数的默认字符集,如 "htmlspecialchars",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1176258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com