ian
ian

Reputation: 12335

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 = '♫'.$tweet.$play_song_url;

Upvotes: 0

Views: 666

Answers (4)

Pascal MARTIN
Pascal MARTIN

Reputation: 401022

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

Upvotes: 4

Jeremy Morgan
Jeremy Morgan

Reputation: 3372

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

echo "You have my ♥ so I'll give you a ♦";

Here is a good list of html character entities.

Upvotes: 0

DisgruntledGoat
DisgruntledGoat

Reputation: 72540

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

Upvotes: 3

cletus
cletus

Reputation: 625097

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

&#8211;

For example: –

Upvotes: 4

Related Questions