Hi,
ok im having some real trouble here..
im trying to load acronyms and thier definitions from a string like this:
$string = 'HTML[+]HyperText Markup Language[-]
PHP[+]PHP hypertext preprocessor[-]
XML[+]Extensible Markup language[-]
CSS[+]Cascading Sylesheets[-] ';
then i want to put them into an associative array and then use str_replace();
to search a string like this:
$string_read = 'this a string it may contain acronyms such as PHP, HTML,XML or even CSS... ';
for acronyms (ie: CSS) and replace them with the correct acronym tag (ie: <acronym title="Cascading Stylesheets">CSS</acronym>
this is the way im tryin to do this...
<?
$string = 'this is a string that contains acronyms like PHP, HTML and CSS';
$nice_string = 'HTML[+]HyperText Markup Language[-]
PHP[+]PHP hypertext preprocessor[-]
CSS[+]Cascading Sylesheets[-] ';
$str_buff = explode('[-]',trim($nice_string));
$acronyms = array();
foreach ($str_buff as $buff) {
list($temp1, $temp2) = explode('[+]', $buff);
$acronyms[$temp1]= '<acronym title="'.$temp2.'">'.$temp1.'</acronym>';
}
echo str_replace(array_keys($acronyms), $acronyms, $string);
?>
but it only seems to do it to 1 of the acronyms this is the output..
this is a string that contains accronyms like PHP, <acronym title="HyperText Markup Language">HTML</acronym> and CSS
can sum1 please help me?