insert html in node titles
Inserting HTML into node titles
Last modified: August 26, 2009 - 23:55
Drupal strips all HTML from node titles when they're displayed to prevent XSS exploits. However, there are some cases where inline HTML elements are needed, such as when titles contain scientific names.
To work around this, we will use pseudotags like [i] and [/i] which Drupal will safely translate into real HTML tags when the page is displayed.
The PHPTemplate file page.tpl.php will need to be edited in order to make this trick work. Specifically, we need to add two new functions.
<?php
function bb2html($text) {
$bbcode = array(
"[strong]", "[/strong]",
"[b]", "[/b]",
"[u]", "[/u]",
"[i]", "[/i]",
"[em]", "[/em]"
);
$htmlcode = array(
"<strong>", "</strong>",
"<strong>", "</strong>",
"<u>", "</u>",
"<em>", "</em>",
"<em>", "</em>"
);
return str_replace($bbcode, $htmlcode, $text);
}
function bb_strip($text) {
$bbcode = array(
"[strong]", "[/strong]",
"[b]", "[/b]",
"[u]", "[/u]",
"[i]", "[/i]",
"[em]", "[/em]"
);
return str_replace($bbcode, '', $text);
}
?>» 12 comments · Read more
