How to convert a string to UTF-16

blacklord
blacklord used Ask the Experts™
on
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,

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Sorry, characters are not displayed correct. Here is another example:

$StringToConvert = 'éêâ';

Commented:
Maybe like yhis:
$s = PDF_utf8_to_utf16(utf8_encode($s));

Author

Commented:
Hello Terref,

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

Commented:
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
@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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial