Function name: sapi_windows_cp_conv()
Applicable version: PHP 4 >= 4.3.0, PHP 5, PHP 7
Function Description: Converting a string from one code page to another
Usage: string sapi_windows_cp_conv ( int $in_codepage , int $out_codepage , string $subject )
parameter:
- in_codepage: The entered code page identifier, indicating the encoding of the input string. Commonly used code page identifiers are:
- CP_ACP: ANSI code page, that is, the system default code page
- CP_UTF7: UTF-7 encoding
- CP_UTF8: UTF-8 encoding
- CP_UNICODE: Unicode encoding
- CP_UTF16LE: UTF-16LE encoding
- CP_UTF16BE: UTF-16BE encoding
- Code page identifiers supported by other Windows systems
- out_codepage: The output code page identifier, indicating the encoding of the output string. The usage method is the same as the in_codepage parameter.
- subject: String to be encoded
Return value: Returns the converted string, and returns false if the conversion fails.
Example:
// 将UTF-8 编码的字符串转换为GBK 编码$utf8Str = "你好,世界!"; $gbkStr = sapi_windows_cp_conv(CP_UTF8, CP_ACP, $utf8Str); echo $gbkStr; // 输出:浣犲ソ锛佸悗闈㈠垎锛? // 将GBK 编码的字符串转换为UTF-8 编码$gbkStr = "浣犲ソ锛佸悗闈㈠垎锛?"; $utf8Str = sapi_windows_cp_conv(CP_ACP, CP_UTF8, $gbkStr); echo $utf8Str; // 输出:你好,世界!
Notes:
- The sapi_windows_cp_conv() function is only available on Windows platforms.
- The code page identifier must be a valid Windows code page identifier, otherwise the conversion will fail.
- This function has been deprecated after PHP 7.2.0 and is not recommended for use in new projects. It is recommended to use the iconv() function instead.