Solved

How to convert a string to UTF-16

Posted on 2006-07-12
7
5,712 Views
Last Modified: 2012-06-21
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,

0
Comment
Question by:blacklord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
7 Comments
 

Author Comment

by:blacklord
ID: 17090632
Sorry, characters are not displayed correct. Here is another example:

$StringToConvert = 'éêâ';
0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17090808
Maybe like yhis:
$s = PDF_utf8_to_utf16(utf8_encode($s));
0
 

Author Comment

by:blacklord
ID: 17091844
Hello Terref,

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

0
 
LVL 29

Expert Comment

by:TeRReF
ID: 17091902
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
 
LVL 14

Accepted Solution

by:
ThG earned 500 total points
ID: 17112784
@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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question