검색시 검색해당 글자에 특정 색상 입히는 작업을 하고 있는데요.
foreach ($data_result["qry"] as $i => $row) {
$data_list[$i]->title = (strpos($searchkey, 'title')) ? search_font(utfChange($row["title"]), $searchvalue) : utfChange($row["title"]);
----생략----
}
보시면 $searchvalue는 검색어 $searchkey 검색 필드입니다.
소스 보시면 searchkey의 검색 필드가 title이면
search_font 함수로 빠져 나가는건데요..
이 함수는 helper 함수로 저장했고 자동으로 불러내도록 했습니다.
function search_font($str, $stx, $tag_open='', $tag_close = '') {
if ($str == '')
return FALSE;
if ($stx != '') {
// 문자앞에 \ 를 붙인다.
$src = array('/', '|');
$dst = array('\/', '\|');
if (!trim($stx)) return $str;
// 검색어 전체를 공란으로 나눈다
$s = explode(' ', $stx);
// '/(검색1|검색2)/i' 와 같은 패턴을 만듬
$pattern = '';
$bar = '';
foreach($s as $row) {
if (trim($row) == '')
continue;
$tmp_str = str_replace($src, $dst, quotemeta($row));
$pattern .= $bar . $tmp_str . '(?![^<]*>)';
$bar = '|';
}
return preg_replace('/('.$pattern.')/i', $tag_open.'\\1'.$tag_close, $str);
// 기존
// return preg_replace('/('.preg_quote($stx, '/').')/i', $tag_open."\\1".$tag_close, $str);
}
return $str;
}
그런데 검색만 잘 되고 아무 반응이 없네요 ㅠ,ㅠ 왜 그런건지 ㅠ,ㅠ
아예 변환이 안된건지 체크해보세요.