Iconv functions in PHP

xiaoxiao2021-03-06  97

Introduction

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 shouth.

demand

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/.

installation

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 change to iconv.dll

Runtime configuration

The behavior of these functions is affected by the global configuration file php.ini.

Form 1. iconv Configuration Options

NameDefaultChangeAbleiconv.input_encodingiconv_input_encodingphp_ini_alliconv.output_encodingiconv_output_encodingphp_ini_alliconv.internal_EncodingCODICONV_INTERNAL_ENCODINGPHP_INI_ALL

For further details and definition of the php_ini_ * constants see

INI_SET ().

Resource Type

The expansion module does not define any resource type.

Predefined constant

Since PHP 4.3.0 It is Possible to Identify at Runtime Which iconv us atopted by this extension.

Table 2. Iconv Constants

ConstantTypedscriptioniconv_Implstringthe Implementation Nameiconv_versionstringthe Implementation Version

Note: Writing Implement-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

DescriptionArray

Iconv_get_encoding ([String Type])

IT returns the current settings of ob_iconv_handler () ARRAY OR FALSE ON FAILURE. The value of the optinal type can be:

ALLINPUT_ENCODINGOUTPUT_ENCODINTERNAL_ENCODING

IF

Type is omitted or not 'all'

Iconv_get_encoding () Returns The Current Settings of

ob_iconv_handler () AS String.

Example 1. Iconv_get_encoding () Example:

Iconv_set_encoding ("INTERNAL_ENCODING", "UTF-8");

Iconv_set_encoding ("Output_Encoding", "ISO-8859-1");

VAR_DUMP (iconv_get_encoding ('all'));

?>

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

DescriptionBool

Iconv_set_encoding (String Type, String Chars)

IT Changes The value of type to charset. Returns true if success, returns false.

The Value of Type Can BE:

INPUT_ENCODINGOUTPUT_ENCODINGINTERNAL_ENCODING

Example 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

Descriptionstring

Iconv (string in_charset, string out_charset, string STR)

IT Converts The string string string in in in. .. It returns the configuration string or false, if IT fails.

Example 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

DescriptionArray

OB_ICONV_HANDLER (String Contents, Int Status)

IT Converts the string encoded in inflect_encoding to output_encoding.

INTERNAL_ENCODING AND OUTPUT_ENCODING SHOULD BE Defined by iconv_set_encoding () or in The Configuration File PHP.ini.

Example 1. OB_ICONV_HANDLER () EXAMPLE:

Ob_start ("ob_iconv_handler"; // start output buffering

转载请注明原文地址:https://www.9cbs.com/read-125297.html

New Post(0)