I am trying to highlight just the begining of words in a string that start with my keyword. So if a user submitted "hat" the word "hatter" would be highlight as such, but the word "that" would not. Any suggestions.
Here is my code that currently highlights every instance of the keyword:
for($i=0;$i<count($keyword2);$i++){
If ($i==0){
$titlestr2=preg_replace("'($keyword2[$i])'si","[:;]\\1[;:]",$titlestr);
}else{
$titlestr2=preg_replace("'($keyword2[$i])'si","[:;]\\1[;:]",$titlestr2);
}
}
for($i=0;$i<count($keyword2);$i++){
$titlestr3 = str_replace("[:;]","<span class=\"highlight2\">",$titlestr2);
$titlestr3=str_replace("[;:]","</span>",$titlestr3);
}
echo $titlestr3;