使用 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;
?>
我想对 $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;
?>