將以下代碼
放到對應的方法的class中(只對當前使用)
或app/index/class.php (前臺全局使用)
或app/class.php (全系統全局使用)
```
/**
* 關鍵詞標紅
* @param type $content 全部內容
* @param type $str 關鍵詞
* @return type
*/
function get_search($content, $str) {
$res = str_ireplace($str, '<span class="red">' . $str . '</span>', $content);
return $res;
}
```
使用方法
```
<?=get_search('所顯示的內容', '這里調用關鍵詞' ?>
```
別忘了style中增加
```
.red {font-style: normal;color: #c00;}
```
或者把 `<span class="red">' . $str . '</span>`改成``<font color=``"#ff0000"``>``' . $str . '``</font>``