4

Possible Duplicate:
How do you print raw UTF-8 characters from their numbers? [PHP]

This code works : echo ' & # 3 4 ; ' will print a double quote on my webpage.

This, on the other hand, is obviously wrong : echo ' U + 2 5 B 2 ' just prints the literal characters.

What is the correct syntax? By the way, that U+25B2 should be an upward pointing triangle. I would like to use it to over an html select with its down triangle.

Community
  • 1
  • 1
MountainMan
  • 753
  • 2
  • 10
  • 20
  • 3
    php's echo doesn't care of what you output. So it outputs the exact bytes you've passed – zerkms Nov 04 '12 at 04:36
  • 2
    As zerkms said, PHP is actually outputting EXACTLY what you tell it to. What's going on behind the scenes is that your browser knows that the " should be translated to a quote. You'll have to use something similar to access the unicode values if you need them. – RonLugge Nov 04 '12 at 04:45
  • Do you want to output the actual character or just HTML special character entity? – Alvin Wong Nov 04 '12 at 05:26
  • The answer mentioned by mgibsonbr, is a good one. From the jumping off points in there, I learned good info; was surprised how much of that was referrenced below by folk who replied. Now I've got a solid black Uppointing triangle to cover the downpointing one of the html select device. And learned about the UTF-8 to hex, prior to echoing. Thx! – MountainMan Nov 04 '12 at 05:58

3 Answers3

1

Add below header in your PHP page. I think it should take care printing the desired character.

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

and echo your value using your UTF char as :

echo "\xE2\x96\xB2";

Please Note: E2 96 B2 UTF-8 equivalent of U+25B2 UTF-16 value for your upward pointing triangle.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • 1
    This is completely incorrect. PHP is not Unicode-aware - `\x25B2` ends up printing as `%B2` (`%` being `\x25`). –  Nov 04 '12 at 05:16
  • @duskwuff: I used the wrong HexCode. Corrected in the answer. Hope its fine now. – Yogendra Singh Nov 04 '12 at 05:22
  • While you're now technically correct, you're still not giving a particularly useful answer -- in particular, you haven't explained where E2 96 B2 comes from. –  Nov 04 '12 at 05:23
  • @duskwuff: Added the note in the answer. – Yogendra Singh Nov 04 '12 at 05:28
1

Do the same as you did with your quote:

echo '&#9650;';

You can find the HTML entity info on FileFormat.Info.

uınbɐɥs
  • 7,236
  • 5
  • 26
  • 42
0

u+25b2 is simply a nicely formated human string, presenting the two bytes of a particular unicode character sequence.. By and of itself, the string form means nothing to a browser, because that's the human version. To see the actual character represented by that code sequence, you have to output the raw bytes, e.g. 0x25 and 0xb2.

Marc B
  • 356,200
  • 43
  • 426
  • 500