How to use search_excerpt() function from core search module?
Try this code.I have just added a space after the string and this will surely work

$string = 'this is a test';   
$test = (search_excerpt('test', $string.' '));
print $test;


In the search_excerpt() if the search text is the last one, then preg_replace omits the search text.In order to overcome this I just added a empty space to the string.

// Highlight keywords. Must be done at once to prevent conflicts ('strong' and '&lt;strong&gt;').
  $text = preg_replace('/' . $boundary . '(' . implode('|', $keys) . ')' . $boundary . '/iu', '&lt;strong&gt;\0&lt;/strong&gt;', $text);