I just tracked some puzzling behavior in my node template to the fact that $title has special characters encoded, e.g., an apostrophe is represented as '.
I now see what is happening, but not why. As I understand it, single-line values are not supposed to be encoded. $title does not contain HTML; why should it be encoded?
I searched Drupal.org for "apostrophe 039" and found no information about why Drupal does this -- not even an explanation addressed to a baffled newbie like myself -- just issue after issue about instances where Drupal encodes various values that it shouldn't. Perhaps this is yet another one?
Given the fact that $title is encoded, how do I un-encode it? I found the check_plain function, which encodes a string, but I can't find the function (I assume there is one) that does the reverse.
Comments
I can enter special
I can enter special characters in titles just fine without using HTML entities. Can you explain what I need to do to see the problem?
Or is the title produced by some contributed module? There have been similar issues, for example with the page_title module here: http://drupal.org/node/124169
Just a plain title
No, it's just a plain old title. Drupal does this all by itself.
I don't think I explained clearly what is happening. Of course you can enter special characters without using HTML entities -- Drupal is converting the characters to HTML entities without telling you. They display correctly because that's what characters entities do (even in cases, like the apostrophe, where they are unnecessary). If you need to perform any type of text manipulation on a title, though... watch out.
In my case I was trying to apply a regular expression to the title, and the apostrophes weren't being processed because my pattern was trying to find an apostrophe, and the title contained «'».
I solved my immediate problem by searching for the character entity instead of the character it represents, but that's pure kludge. I need to be able to convert the escaped string back to an un-escaped string, do my business, and reconvert it.
Hmm... but Greek are
Hmm... but Greek are "special characters", there are HTML entities for all of them, but the HTML output simply outputs them as they are, in UTF8. I can see no HTML entities in the HTML source.
Maybe you are using some PHP functions which are not utf8-aware or using non-Unicode character codes for special characters? Just a thought.
-----------
Edited:
You are right, I misunderstood. That was not about non-ascii characters but about characters which are special in HTML and PHP.
I vaguely understand that it is a security issue (perhaps an apostrophe could terminate php strings when processes). There is some explanation in the second one of these
http://api.drupal.org/api/function/check_plain/6
http://api.drupal.org/api/function/drupal_validate_utf8/6
but I haven't given it much thought.
There is a PHP function for decoding: http://php.net/html_entity_decode
I had this problem as well.
I had this problem as well. I had done some preprocessing of pages where I changed the page's title using $vars['title'] rather than $vars['node']->title.
I followed the method that
I followed the method that @bricestacey used and found that it worked. However I then realised that the header was also displaying as html entities. I fixed this by replacing the default title tag found in the html.tpl.php
print$head_title;withprint html_entity_decode($head_title). This fixed the issue. Most probably not secure though.