How to convert a string to UTF-16

Hi Everyone,

I wonder how I can convert a normal string to UTF-16 encoding? This should be done without using PHP's mb functions.

Thanks!

Let's say I have this string and want it to use in UTF-16:

$StringToConvert = 'ÜĞİŞÇÖé';

Thanks,

blacklordAsked:
Who is Participating?
 
ThGCommented:
@TeRReF: sorry but that information is not right.

PHP actually has a builtin module for charset conversions, but it is not compiled by default. Sometimes i have to upload it to the ftp and load it via dl("iconv.so")

$utf16 = iconv("iso-8859-1", "utf-16", $str);

of course you need to supply the right input charset, and you must know it in advance.
0
 
blacklordAuthor Commented:
Sorry, characters are not displayed correct. Here is another example:

$StringToConvert = 'éêâ';
0
 
TeRReFCommented:
Maybe like yhis:
$s = PDF_utf8_to_utf16(utf8_encode($s));
0
 
blacklordAuthor Commented:
Hello Terref,

What is PDF_utf8_to_utf16 function? Is it a standard function or does it require a PHP module?

0
 
TeRReFCommented:
It's not standard built-in, you're right. PHP has no built-in functions that can convert to UTF-16 (as far as I know).
You can find more info here:
http://nl2.php.net/manual/en/ref.pdf.php
http://www.pdflib.com/products/pdflib/index.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.