2010年2月25日 星期四

搜尋並取代字串(關鍵字變紅色)

<?php
function searchReplace($content,$keyword){
$change = ereg_replace ( $keyword, '<strong><span class="search13">'.$keyword.'</span><strong>', $content);
return $change;
}
?>

CSS

.search13 {
text-transform: none;
color: #FF0000;
font-size: 13px;
letter-spacing: 0.1em;
text-indent: 1px;
word-spacing: 0.6em;
}

用法
1.先配合MySql搜尋(看自己的記憶碎片第六片-php關鍵字搜尋)
2.searchReplace($row_RecNews['news_content'] ,$_GET['keyword']);
3.那個keyword是從上一頁GET過來的
4.可配合切割中文字元

沒有留言:

張貼留言