Tidying search results from database php

落花浮王杯 提交于 2019-12-06 19:35:23

You can do something like this:

In the PHP script

$keyword = THESEARCHEDKEYWORD;
$pattern = "/([^a-z])$keyword([^a-z])/i";
$highlight = '<span class="highlight">' . $keyword . '</span>';
foreach ($searchcontent->result() as $row)
{
   $title = preg_replace($pattern, "$1$highlight$2", $title);
   $content = preg_replace($pattern, "$1$highlight$2", $content);
   echo $title;
   echo $content;
}

And then add this rule in the CSS:

.highlight
{
   font-weight: bold;
   background-color: yellow;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!