• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1177
  • Last Modified:

how to represent unicode characters in strings

hi all,
concerning unicode how can I represent unicode string in php
say  those 3 letters:
U+0644
U+0647
U+062C

how can I express them in php

best regards
HG
0
shang3000
Asked:
shang3000
  • 3
  • 2
  • 2
  • +1
5 Solutions
 
steelseth12Commented:
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");
0
 
shang3000Author Commented:
it does not give the same result as this (please check this image)
http://q.softwarelab.net/test.png

and here is what your code display
http://q.softwarelab.net/test2.png

best regards
HG
0
 
steelseth12Commented:
shang3000 do you have some samples of the characters and their codes.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
nizsmoDeveloperCommented:
shang3000:

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:
UTF-8
The W3C's recommended encoding. Can represent all characters defined in the Unicode standard.

windows-1252
Windows 1252 (no Arabic characters included)

windows-1256
Windows Arabic codepage

asmo-708
ASMO 708 codepage

dos-720
Arabic DOS 720 codepage


For a big list of charsets:
http://a4esl.org/c/charset.html
0
 
shang3000Author Commented:
hi nizsmo,
thanks for reply,

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

http://q.softwarelab.net/test3.png
gives me  different   than
http://q.softwarelab.net/test.png
please help me

best regards
HG

0
 
nizsmoDeveloperCommented:
i'm not too sure which encoding your character is in.

http://q.softwarelab.net/test.png
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.
0
 
shang3000Author Commented:
unfortunately it's a page of a book in safari books online on unicode not a source code
0
 
ussherCommented:
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.
<?php
   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
http://konieczny.be/unicode.html

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?
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now