Forum und email

unicode_encode

(No version information available, might be only in CVS)

unicode_encode — Convert a unicode string in any encoding

說明

string unicode_encode ( unicode $input , string $encoding [, int $errmode ] )

Takes a unicode string and converts it to a string in the specified encoding .

參數

input

The unicode string that is converted.

encoding

The new encoding for input .

errmode

Conversion error mode. This parameter determines the action to take when the converter cannot convert a character. For a list of available modes, refer to unicode_set_error_mode(). If the parameter is not set, the global error mode is used.

Return值

A string on success, or FALSE on failure.

錯誤/例外

Emits a E_WARNING level error if a converter cannot be created for the desired encoding .

範例

Example#1 A unicode_encode() example

Note: The characters will be seen instead of entities in the output.

<?php
header 
('Content-Type: text/plain; charset=ISO-8859-2');

$encoded unicode_encode ('\u0150\u0179''ISO-8859-2');

echo 
'Unicode semantics: 'ini_get ('unicode_semantics'), PHP_EOL;
echo 
'The string itself:'$encodedPHP_EOL;
echo 
'The length of the string: 'strlen ($encoded);
?>

上例的輸出類似於:

Unicode semantics: 1
The string itself: &#336;&#377;
The length of the string: 2

註釋

Warning

本函式是實驗性的。這個函式的行為、名稱、和關於此函式的任何其他文件在未來PHP的發行中可能會在不通知的情況下改變。 使用此函式需自行承擔風險。