php中的iconv functions

介绍

This module contains an interface to the iconv library functions. The iconv library functions convert strings between various character sets encodings. The supported character sets depend on the iconv() implementation on your system. Note that the iconv() function on some systems may not work as well as you expect. In this case, you should install the libiconv library.

需求

Your systems standard C library must provide the iconv() function or you must have libiconv installed on your system. The libiconv library is available from http://www.gnu.org/software/libiconv/.

安装

To be able to use the functions defined in this module you must compile your PHP interpreter using the configure line --with-iconv[=DIR].

Note to Win32 Users: In order to enable this module on a Windows environment, you must copy iconv-1.3.dll from the DLL folder of the PHP/Win32 binary package to the SYSTEM32 folder of your windows machine. (Ex: C:/WINNT/SYSTEM32 or C:/WINDOWS/SYSTEM32). Starting with PHP 4.2.1 the name changed to iconv.dll

运行时配置

这些函数的行为受到全局配置文件 php.ini 的影响。

表格 1. Iconv configuration options

NameDefaultChangeable
iconv.input_encodingICONV_INPUT_ENCODINGPHP_INI_ALL
iconv.output_encodingICONV_OUTPUT_ENCODINGPHP_INI_ALL
iconv.internal_encodingICONV_INTERNAL_ENCODINGPHP_INI_ALL
For further details and definition of the PHP_INI_* constants see ini_set().

资源类型

该扩展模块未定义任何资源类型。

预定义常量

Since PHP 4.3.0 it is possible to identify at runtime which iconv implementation is adopted by this extension.

表格 2. iconv constants

constanttypedescription
ICONV_IMPLstringThe implementation name
ICONV_VERSIONstringThe implementation version

注: Writing implementation-dependent scripts with these constants should be discouraged.


iconv_get_encoding

(PHP 4 >= 4.0.5)

iconv_get_encoding -- Get current setting for character encoding conversion

Description

array iconv_get_encoding ( [string type])

It returns the current settings of ob_iconv_handler() as array or FALSE on failure. The value of the optinal type can be:

all
input_encoding
output_encoding
internal_encoding

If type is omitted or not 'all' iconv_get_encoding() returns the current settings of ob_iconv_handler() as string.

例子 1. iconv_get_encoding() example:

<pre>
<?php
iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
var_dump(iconv_get_encoding('all'));
?>
</pre>

The printout of the above program will be:

Array

(

    [input_encoding] => ISO-8859-1

    [output_encoding] => ISO-8859-1

    [internal_encoding] => UTF-8

)

iconv_set_encoding

(PHP 4 >= 4.0.5)

iconv_set_encoding -- Set current setting for character encoding conversion

Description

bool iconv_set_encoding ( string type, string charset)

It changes the value of type to charset. 如果成功则返回 TRUE,失败则返回 FALSE

The value of type can be:

input_encoding
output_encoding
internal_encoding

例子 1. iconv_set_encoding() example:

iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");

iconv

(PHP 4 >= 4.0.5)

iconv -- Convert string to requested character encoding

Description

string iconv ( string in_charset, string out_charset, string str)

It converts the string str encoded in in_charset to the string encoded in out_charset. It returns the converted string or FALSE, if it fails.

例子 1. iconv() example:

echo iconv("ISO-8859-1","UTF-8","This is a test.");

ob_iconv_handler

(PHP 4 >= 4.0.5)

ob_iconv_handler -- Convert character encoding as output buffer handler

Description

array ob_iconv_handler ( string contents, int status)

It converts the string encoded in internal_encoding to output_encoding.

internal_encoding and output_encoding should be defined by iconv_set_encoding() or in the configuration file php.ini.

例子 1. ob_iconv_handler() example:

ob_start("ob_iconv_handler"); // start output buffering

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值