Hi,

I've found a acronym generating PHP script and I'd like to add it to my Drupal theme. Does anyone know if how to do this? I've added it to my template.php hoping it would just work, but of course, I wouldn't..

Heres the PHP code:

<?php
function sortr_longer($first, $second) {
	return (strlen($first) < strlen($second)) ? 1 : -1;
}
function acronymit($text) {
	$acronyms = array(
		'WYSIWYG' => 'what you see is what you get',
		'XHTML' => 'eXtensible HyperText Markup Language',
		'CMS' => 'Content Management System'
	);
    uksort($acronyms, 'sortr_longer'); // comment out if already sorted
    foreach ($acronyms as $acronym => $definition) {
        $text = preg_replace("#$acronym(?!</(ac|sp))#", "<acronym title=\"$definition\">$acronym</acronym>", $text, 1);
        $text = preg_replace("#$acronym(?!</(ac|sp))#", "<span class='caps'>$acronym</span>", $text);
    }
    return $text;
}
?>

Thanks for any help!

Comments

nancydru’s picture

dellintosh’s picture

I've recently released an Acronyms module, available for 5.x and 6.x. I think it will help out with what you need, if you are still looking for a solution.

I might be extending this to include the replacement system also (currently it's offered as a management solution for the acronyms and the main target (my client) wanted to simply find the acronyms in a set of thousands of records).

Please feel free to share any ideas you have for enhancements on the project issue queue. :)

-dellintosh