Hi guys
I need your help I have an array with a list of common acronyms as keys, and the unabbreviated equivalents as the values, e.g.
$Acronyms = array(
"P4" => "Pentium 4",
"PC" => "Personal Computer"
...
);
The idea is to pass a piece of text to a simple function, and to use str_replace() to replace any matching acronyms with some HTML code (e.g. PC would become <acronym title="Personal Computer">PC</acronym>).
I have a very simple function to do this, but the only problem is I cannot seem to replace the matching values with anything other than the array value itself, e.g.
[b]// Works ...[/b]
function Acronyms ($String)
{
return str_replace(array_keys($Acronyms), array_values($Acronyms), $String);
}
[b]// Does not work ...[/b]
function Acronyms ($String)
{
return str_replace(array_keys($Acronyms), '<acronym title="'.array_values($Acronyms).'">'.array_keys($Acronyms).'</acronym>', $String);
}
Is there any way I can solve this problem short of ...
-
Adding the HTML code to every value in the acronyms array
-
Using preg_replace() or something similarly over the top
Any help or suggestions would be greatly appreciated.
Thank you in advance
Jonty
P.S. Am I likely to place much strain on the server if the acronyms array contains ~100 keys, and function is called to parse, say, ~5kb of text every time the page is hit?