Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


how to represent unicode characters in strings

Posted on 2007-11-15
Medium Priority
Last Modified: 2012-08-13
hi all,
concerning unicode how can I represent unicode string in php
say  those 3 letters:

how can I express them in php

best regards
Question by:shang3000
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
  • 3
  • 2
  • 2
  • +1
LVL 20

Accepted Solution

steelseth12 earned 800 total points
ID: 20287557
This function is take from http://www.php.net/manual/en/function.chr.php

function uchr ($codes) {
    if (is_scalar($codes)) $codes= func_get_args();
    $str= '';
    foreach ($codes as $code) $str.= html_entity_decode('&#'.$code.';',ENT_NOQUOTES,'UTF-8');
    return $str;

echo uchr("0647");

Author Comment

ID: 20287740
it does not give the same result as this (please check this image)

and here is what your code display

best regards
LVL 20

Assisted Solution

steelseth12 earned 800 total points
ID: 20288218
shang3000 do you have some samples of the characters and their codes.
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!

LVL 21

Assisted Solution

nizsmo earned 800 total points
ID: 20297327

You may need to define your charset to display the character properly?

To do this:

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1256">

You can test out different charset values, to see which one would display your character properly.

These are some of the basic ones:
The W3C's recommended encoding. Can represent all characters defined in the Unicode standard.

Windows 1252 (no Arabic characters included)

Windows Arabic codepage

ASMO 708 codepage

Arabic DOS 720 codepage

For a big list of charsets:

Author Comment

ID: 20306839
hi nizsmo,
thanks for reply,

>>><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1256">

gives me  different   than
please help me

best regards

LVL 21

Assisted Solution

nizsmo earned 800 total points
ID: 20306848
i'm not too sure which encoding your character is in.

is this picture a screenshot of a website? if it is, you may be able to go into the source code of that website and see what encoding they are using.

Author Comment

ID: 20311048
unfortunately it's a page of a book in safari books online on unicode not a source code

Assisted Solution

ussher earned 400 total points
ID: 20333763
Hi HG,

I dont fully understand what it is you are trying to do but i use utf-8 a lot for my websites and here are some things that are useful.

Put this as the first line of any page that is going to be viewed on the web. It tells browsers that the page uses unicode.  IE6 in particular sometimes has problems if you use only the html metatag for this.
   header('Content-Type: text/html; charset=utf-8');

now your page is being displayed in unicode.  

When you are writing your php script it is also important to save it in unicode format. for example if you are writing it with a text editor like notepad you can select 'Save As' and the default option for encoding is is ASCII.  Scroll down the list and select UTF-8.

If you do it like this the document that you are creating can have characters in any language in clear display on the screen so that you can read it while programming.  If you store everything in raw unicode then you wont be able to read the source code.

if are wanting to transform those arabic characters into ones that will display in a document that is not unicode then there is an encoder here

It really depends on how you are getting the unicode.  Is it coming to your php through a form that is submitted on your website? Or are you trying to use php to build a decoder so that you can take the U+123 characters and read them.

How are you getting the unicode that you want to display?

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

636 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