I have the following code to highlight keywords that are found in a string. The only problem is that I only want to highlight the keywords when they are at the begining of a word. (Example: $keyword[0] = "test"... "testing", "test ", "tester", but not "attest", "newtest".) currently the following code highlights any occurance of the keywords. Thanks.
$excerptstr= trim(stripslashes($row['ABSTRACT']));
If (isset($mykeyword) && trim($mykeyword)=="Go"){
for($i=0;$i<count($keyword2);$i++){
If ($i==0){
$excerptstr2=preg_replace("'($keyword2[$i])'si",
"<span class='highlight2'>\\1</span>",$excerptstr);
}else{
$excerptstr2=preg_replace("'($keyword2[$i])'si",
"<span class='highlight2'>\\1</span>",$excerptstr2);
}
}
echo $excerptstr2;
}else{
echo $excerptstr;
}