tags:

views:

85

answers:

4

Symbols such as: ♫

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

So that I can do something like:

 $tweet = '♫'.$tweet.$play_song_url;
+4  A: 

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

–

For example: –

cletus
You can use a numeric character reference like this regardless of the page's charset. Using UTF-8 allows you to include `–` as a simple direct character instead of the escape.
bobince
+4  A: 

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 ^^

Pascal MARTIN
What about URL encoding: `%E2%99%AB` I could not find a HTML entity for the note symbol and when I passed `♫ to twitter it did not decode it until after the posting of the tweet. However when I use the URL encoding it decodes it correctly... Although it show up as a box in the url...
ian
+3  A: 

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">
DisgruntledGoat
A: 

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.

Jeremy Morgan