lets say
$keyword = obama
$result = "US President Barack Obama on Wednesday signed a landmark law"
How do i make that everytime $keyword appears inside $result it changes the $keyword to be inside <strong></strong> tags?
str_replace doesn't work because if the keyword is in lowercaps and the result obama is in higuer caps it wouldnt replace it.
Thanks
edit: found the answer, in case anyone needs it this is the code
$myWords = array($keyword);
function boldText($arrWords, $strSubject)
{
if (!is_array($arrWords)) return;
foreach ($arrWords as $strWord)
{
$strSubject = preg_replace('@(' . preg_quote($strWord, '@') . ')@i', "<b>\\1</b>", $strSubject);
}
return $strSubject;
}