PHP Dokumentation: Function unicode-encode
12. Januar 2010 von werner
unicode_encode
(PHP 6 >= 6.0.0)
unicode_encode — Convert a unicode string in any encoding
Beschreibung
Takes a unicode string and converts it to a string in the specified encoding.
Parameter-Liste
- 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.
Rückgabewerte
A string on successIm Fehlerfall wird FALSE zurückgegeben..
Fehler/Exceptions
Emits a E_WARNING level error if a converter cannot be created for the desired encoding.
Beispiele
Beispiel #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
'The string itself:', $encoded, PHP_EOL;
echo 'The length of the string: ', strlen ($encoded);
?>Das oben gezeigte Beispiel erzeugteine ähnliche Ausgabe wie:
The string itself: ŐŹThe length of the string: 2
Anmerkungen
Diese Funktion istEXPERIMENTELL. Das Verhalten, der Funktionsname und allesAndere, was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohneAnkündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion aufeigenes Risiko.
Siehe auch
- unicode_set_error_mode() – Set the error mode for strings conversions
- unicode_decode() – Convert a binary string into a Unicode string