ciao ragazzi ho una funzione che data in ingresso un testo ed una keyword da ricercare, ti evidenzia tutte le occorrenze della parola nel testo ma ho un problema...ovvero la parola mi viene sostituita con quella in ingresso data come keyword..come faccio a lasciare quella originale?
La funzione è questa:
Codice PHP:
<?php
# funzione che evidenzia il testo che viene dato in input e ti restituisce il numero di occorrenze trovate
function hightlight($str, $keywords = '')
{
$valueToReturn=array();
$the_count = 0;
$keywords = preg_replace('/\s\s+/', ' ', strip_tags(trim($keywords))); // filter
$style_i = 'highlight_important';
/* Apply Style */
$var = '';
foreach(explode(' ', $keywords) as $keyword)
{
$replacement = "$keyword"; #"<span class='".$style."'>".$keyword."</span>";
$var .= $replacement." ";
$str = str_ireplace($keyword, $replacement, $str);
}
/* Apply Important Style */
$str = str_ireplace(rtrim($var), '[b]'.$keywords.'[/b]', $str, $count);
$the_count = $count + $the_count;
#echo"trovate num $the_count occorrenze
";
$valueToReturn[] = $str;
$valueToReturn[] = $the_count;
return $valueToReturn;
}
?>