What improvements can be made to the highlight function to address the case sensitivity issue?
The issue with the highlight function is that it is case sensitive, meaning it will only match exact cases of the search term. To address this issue, we can modify the highlight function to perform a case-insensitive search by using the stripos() function instead of strpos().
function highlight($text, $searchTerm) {
$highlightedText = $text;
$pos = stripos($text, $searchTerm);
if ($pos !== false) {
$highlightedText = substr_replace($text, '<span style="background-color: yellow;">'.substr($text, $pos, strlen($searchTerm)).'</span>', $pos, strlen($searchTerm));
}
return $highlightedText;
}