3

I've a text content in "xyz" language.

<p style="font-family:xyz;"> eWvS³: kmwkMnsâ kq¸Àt^mWmb KmeIvkn kocoknsâ aq¶mw]Xn¸v </p>
// It will not display correctly as font is not embedded.

here the font xyz (xyz.ttf) is non unicode.

Now I want to convert that "XYZ" (xyz.ttf) font text to unicode "PQR" (pqr.ttf) font

Simply, a non-unicode Chinese (non_uni_chinese.ttf) to uniocode Chinese (uni_chinese.ttf)

how can I make it possible using php. any help?

TheKid
  • 349
  • 1
  • 3
  • 8
  • are you sure that "xyz.ttf" has unicode characters? the normal characters are rendered normally? –  May 27 '12 at 12:09
  • "xyz.ttf" is a non-unicode font and "pqr.ttf" is unicode. The text "eWvS³: kmwkMnsâ kq¸Àt^mWmb...." is currently in non-unicode "XYZ" font – TheKid May 27 '12 at 12:22

2 Answers2

2

You must do this "character by character".

It's mean you must replace every character in "non-Unicode Chinese" font to Unicode font. I don't know much about Chinese, but in Vietnam, they use this way:

  1. Write a string that contains "non-Unicode" font by an Unicode font, and these characters will not display correctly. For example: Ñaây laø Tieáng Vieät <- this is a non-Unicode Vietnamese write with an Unicode font.
  2. Replace "character by character". For example: Ñ = Đ; aâ = â; aø = 2;...
  3. Then we have this result: Đây là Tiếng Việt.

Of course we don't do it step-by-step, we use a software called "Unikey" to do this.

And I'm sure that there is a software to do that in Chinese. The point here is you must "do" it again in PHP.

Here come something can help you: http://www.pinyin.info/tools/converter/chars2uninumbers.html

Good luck.

Tony Dinh
  • 6,668
  • 5
  • 39
  • 58
  • Thanks TrungDQ, that sounds logical and I've started coding accordingly. thanks for the conversion tool too. – TheKid May 29 '12 at 13:53
0

Generated output should use one encoding. It's not proper solution, but anyway, for converting string to different encoding you should use iconv function http://www.php.net/manual/en/function.iconv.php

Ivan Fateev
  • 1,032
  • 1
  • 10
  • 26
  • Im also thought of iconv(). but don't know how to do it properly. can explain a bit more. thanks – TheKid May 27 '12 at 12:25
  • before do iconv you need to know the encoding of this string? language i mean. –  May 27 '12 at 12:44
  • encoding? I've both fonts, I've the string, I know it's in "xyz" language. Say: a non-unicode Chinese (non_uni_chinese.ttf) to unocode Chinese (uni_chinese.ttf). is that clear dear. thanks – TheKid May 27 '12 at 13:09
  • iconv can't convert non-uniqode encoding to unicode. You should specify encoding of the source string and result encoding (in your case it's utf-8 i guess). As alternative you may use mb_detect_encoding function of the multibyte library extension of the php to detect encoding of the source text http://php.net/manual/en/function.mb-detect-encoding.php and mb_convert_encoding as alternative to iconv. But according to my experience these functions often do stuff the wrong way. I don't understand one thing: why you use different encodings on your page? – Ivan Fateev May 27 '12 at 16:30
  • @JohnPoison the non-unicode string is from a remote url and I need to convert it to unicode for palm devices. – TheKid May 29 '12 at 13:53