使用strpos进行搜索,然后突出显示匹配的字母


Use strpos to search and then highlight the matched letters

我想对$search字符串执行搜索,然后显示整个$search串并突出显示匹配的字母。

这是迄今为止的代码:

//The user input
$user_input= $_POST['user_input'];
//The search
$search = 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'; 
$match = strpos($search, $user_input);
echo '$match';
?>
    <?php
    //The search
    $testar = 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.'; 
    $match = str_replace($_POST['user_input'], '<b>' . $_POST['user_input'] . '</b>', $testar);
    echo $match;
     ?>