- preg_quote: documentation ( source)
- preg_replace: documentation ( source)
<?php
function bolder($word, $sentence){
$result = preg_replace('~\b(' . preg_quote($word, '~') . ')\b~i', '<span class="found">$1</span>', $sentence);
return $result;
}
$query = 'google';
$description = 'google this and that okay';
$thing = bolder($query, $description);
echo $thing;