开发者

how do i encode symbols in my html and php

Symbols such as: ♫

http://www.chatsmileysemoticons.com/music-symbol-twitter/

So that I can do something like:

    $tweet 开发者_StackOverflow= '♫'.$tweet.$play_song_url;


If you are writting your PHP source code in UTF-8, you can directly use that "special" character :

header('Content-type: text/html; charset=UTF-8');

$tweet = '♫' . ' Hello !';
echo $tweet;

Will get you the expected output -- I've just tried.

Note that your browser must, of course, display the page as UTF-8 -- this explain why I sent the correct header.


You can also use the HTML code of the character you want, and use html_entity_decode to convert them to a single character :

header('Content-type: text/html; charset=UTF-8');
$tweet = html_entity_decode('♫', ENT_COMPAT, 'UTF-8') . ' Hello !';
echo $tweet;

The problem being finding the right HTML-entity code ^^


They're Unicode characters. Just make sure your HTML is UTF-8 and you can then use entities like:

–

For example: –


You can do one of two things:

  1. Use HTML entities, these are the one you'll need: ♩ ♪ ♫ ♬ ♭ ♮ ♯
  2. Encode your page as UTF8 and insert the symbols directly. You can do with with a meta tag in the <head> section of your HTML: <meta http-equiv="Content-Type" content="text/html; charset=utf-8">


You can just echo out the html character entities, if supported. Something like

echo "You have my &hearts; so I'll give you a &diams;";

Here is a good list of html character entities.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜