My database has a table with 1000 terms and their definitions.
I want to print those definitions and add a span tag to every word that is already a term.
I use this to create the two arrays (patterns and replacements):
while($row = mysql_fetch_array($rsd)){
$patterns[$i] = '/'.$row['term'].'/';
$patterns[$i+1] = '/<span class="linkedterm"><span class="linkedterm">'.$row['term'].'</span>/';
$replacements[$i+1] = '<span class="linkedterm">'.$row['term'].'</span>';
$replacements[$i] = '<span class="linkedterm">'.$row['term'];
$i = $i + 2;
}
And this to echo the definitions:
echo preg_replace($patterns, $replacements, $row['definition']);
- With this code i have an error for character /, at the close span tag. So I want a solution for this, to be able to pass a value with / char. Or any other solution that I may have missed.
Thanks
1 Answer