PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

unicode_semantics> <i18n_loc_set_default
Last updated: Wed, 03 Jun 2009

view this page in

unicode_encode

(PHP 5 CVS only)

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

Description

string unicode_encode ( unicode input, string encoding )

Warning

This function is currently not documented; only the argument list is available.

Parameters

input

Its description

encoding

Its description

Return Values

What the function returns, first on success, then on failure.

Examples

Example 1. A unicode_encode() example

Any text that describes the purpose of t

<?php
if ($anexample === true) {
    echo
'Use the PEAR Coding Standards';
}
?>

The above example will output:

Use the PEAR Coding Standards

See Also

unicode_decode()



add a note add a note User Contributed Notes
unicode_encode
shidapu at mail dot ru
24-Jul-2006 06:10
convert unicode string to any chatacter set

<?
   
function unicode_convert($str, $out_encoding)
    {
       
$ret = '';
        for(
$i=0; $i < strlen($str) / 2; $i++)
        {
           
$dec = ord($str[$i*2])+256*ord($str[$i*2+1]);
            if (
$dec < 128)
            {
               
$utf = chr($dec);
            }
            elseif (
$dec < 2048)
            {
               
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
               
$utf .= chr(128 + ($dec % 64));
            }
            else
            {
               
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
               
$utf .= chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
               
$utf .= chr(128 + ($dec % 64));
            }
           
$ret .= $utf;
        }
       
$ret = iconv('utf-8', $out_encoding, $ret);
        return
$ret;
    }
?>
Hugo Dworak (post at o2 dot pl)
23-Nov-2005 08:54
As for an example of the usage of the function unicode_encode:

<?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, 'The string itself: ';
 
printf ($encoded . PHP_EOL, '%s');
  echo
'The length of the string: ', strlen ($encoded);
?>

The above example will output (please note that there will be characters instead of entities in the output):

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

unicode_semantics> <i18n_loc_set_default
Last updated: Wed, 03 Jun 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites