I would like to know if there's a way to display special characters in the title of category items. I haven't been able to find reference to it in the forums. Thanks.

Comments

nancydru’s picture

If you know the ASCII value, you can include &#nnn. The other way I've done it is kind of kludgey, but it works. I open Word and type it, then cut and paste.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

mckay024’s picture

Thanks for the reply Nancy! I gave the ASCII value a try but it just displayed it as written. I also tried enclosing it < > and using PHP to write it but to no avail. The text I'm trying to display is a category title called Empress Jingū (which displays fine here). The site is www.clioproject.org, and the page is under View the Collection/Person.

Thanks in advance for any help/suggestions!

nancydru’s picture

About the only other thing I can suggest is the technique of using Word that I mentioned.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

mooffie’s picture

I would like to know if there's a way to display special characters in the title of category items. I haven't been able to find reference to it in the forums. Thanks.

There are no special characters. All characters are equal. You won't find a reference in the forums.

If you know the ASCII value [...]

Only a tiny fraction of the characters have an ASCII value. We're dealing with Unicode, not with ASCII.

[...] you can include &#nnn.

Don't. The ampersand has a special meaning in HTML. Drupal escapes it in some places. And Drupal's search engine would have it break the word in two.

The text I'm trying to display is a category title called Empress Jingū (which displays fine here).

Maybe your database is encoded incorrectly. If you paste the text from here into a body of a node on your website, does it show up correctly when you view the node? What version of MySQL are you using?

jayrb’s picture

http://www.w3.org/TR/REC-html40/sgml/entities.html

Yes, the & does have special meaning in HTML - declaring special entities!!!!

"Drupal escapes it in *some* places."

This is driving me crazy debugging the different conditions. Sometimes it works and others it doesn't. Make a choice and stick with it. Sometimes the raw character works (and it shouldn't) and other times the friendly or numeric codes simply will not.

One place that is definitely an issue is the l() call.

adam_b’s picture

There's no problem as long as you're using UTF-8 encoding, which is standard for Drupal 5. You should be able to paste special characters directly into the field.

To be sure you're getting the right ones (assuming you're working on Windows):
- go to the Character Map
- tick the Advanced View checkbox
- change the character set to Unicode
- find the character you want (the font doesn't matter)
- copy it and paste it into the Drupal form field

I just double-checked and it works for categories names tóòst, БЖЌЊ, and ⅜◊●□‡

mckay024’s picture

I'm using Drupal 5, MySQL version 4.1.10. I checked my database and found a mix of collation settings, some utf_general_ci and some latin1_sweedish_ci. The table with the category titles seemed to be set correctly but still doesn't display properly (I get a question mark where the "u" should be. The copy/paste from Word method works great for the body area, just not for the title.

I can see the character when previewing, but as soon as I submit I get a question mark.

adam_b’s picture

I was able to do this fine on a WAMP installation using Uniform Server, but now I'm having the same problem - not just with category titles, but with any text - previewing is fine, but saving Arabic turns it all to ???????, although the database and collation encoding seem to be set correctly. More at http://drupal.org/node/164284

redhatmatt’s picture

love it, all you guys say, "should work" but it doesn't. As the guy said the body can display ascii characters but I have tried now for a few hours to look over the past 3 years of Drupal conversations on ascii and utf issues in the title and NO ONE ever gives a real answer. Rather you keep your untested comments to yourself, than have to dig through your flippant disregard for the value of actually knowing what you are talking about. And yes, WHEN I do find the answer, and I will, I will post it... HERE.

redhatmatt’s picture

Ok, I came back... hopefully this helps someone, I added to someone elses stuff, but this does the trick (poor guy with the question looks like it's been over a year plus since anyone took the situation seriously) the other post is http://drupal.org/node/28537 and was written on the subject of some book module, but I used all this and it does in fact work...

Go to your template.php file in your themes folder for the them you are using and open it... right after the initial php opening tag line 1:


function bb2html($text) {
 $bbcode = array(
 "[strong]", "[/strong]",
 "[b]", "[/b]",
 "[u]", "[/u]",
 "[i]", "[/i]",
 "[em]", "[/em]",
 "[amp]", "[theta]", "[degree]", "[prime]", "[doubleprime]", "[squareroot]"
 );
 $htmlcode = array(
 "<strong>", "</strong>",
 "<strong>", "</strong>",
 "<u>", "</u>",
 "<em>", "</em>",
 "<em>", "</em>",
 "&amp;", "&theta;", "&#176;", "&prime;", "&Prime;", "&radic;"
 );
 return str_replace($bbcode, $htmlcode, $text);
}

function bb_strip($text) {
 $bbcode = array(
 "[strong]", "[/strong]",
 "[b]", "[/b]",
 "[u]", "[/u]",
 "[i]", "[/i]",
 "[em]", "[/em]",
 "&amp;", "&theta;", "&#176;", "&prime;", "&Prime;", "&radic;"
 );
 return str_replace($bbcode, '', $text);
}

Save it...

then open up page.tpl.php and find the lines that mention $title... basically we want to slip in 

<?php print bb2html($title); 

there but modify what is actually in YOUR page.tpl.php file... in my instance I was using plain old Garland (yippee!)

so I found:
if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif;
around line 68
and replaced it with:

 if ($title): print '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. bb2html($title) .'</h2>'; endif; 

Finally put this (as he said before) between the title tags at the top to strip the [whatever] items out of your title...

<?php print bb_strip($head_title); 

Ok so that's it, hopefully you can get through the patterns now... if you still have issues I will subscribe to this thread or just contact me, for my instance I needed only scientific special characters... so I am going to make a completed list of characters and post the whole thing here when I am done, so whomever will not have to do the same work again...

federico’s picture

Hello,

I want to insert special characters in node content, like μ φ . In my page, those characters are replaced by ?.

I've checked the characters collation of the node_revisions table, and the body field has the collation latin1_swedish_ci. Is this collation right?

I've checked the content of this field, using phpmyadmin, and it seems that the special characters are not stored: in the database they are replaced by ?. So this is not a problem of the drupal theme.

I see that in drupal.org (emm.. in this comment for example μ φ) , special characters are shown right. How can I archieve this in my page (please, I know I can input &micro; instead of µ, but my users don't. )

I'll appreciate any advice on this.

Thanks,

===
more info: I've manually entered special characters in the database table (using phpmyadmin) and those characters are shown right. It seems that drupal is filtering somehow those characters, before saving the content to the database. I've disabled "html corrector" filter, but this issue is still there.

nancydru’s picture

Drupal seems happier with utf8_general_ci.

gagarine’s picture

This is a bug and their is a patch #1555294: Vocabulary title HTML entities are double encoded with some luck it will soon be fixed.

https://interface-network.com - Interface Network is an action and research technology governance agency.