함수 highlight()

함수 highlight()

1 JavaScript[ | ]

function highlight(needle, haystack) {
    var re = new RegExp(needle, 'gi');
    return haystack.replace(re, function(str) {return '<span style="background:yellow">'+str+'</span>'});
}
function highlight(needle, obj) {
    var re = new RegExp(needle, 'gi');
    obj.innerHTML = obj.innerHTML.replace(re, function(str) {return '<span style="background:yellow">'+str+'</span>'});
}

2 PHP[ | ]

function highlight($needle, $haystack, $background_color='yellow') {
    if($needle == '') return $haystack;
    return preg_replace( '#' . preg_quote($needle,'#') . '#iu',
        '<span style="background:'.$background_color.'">$0</span>',
        $haystack );
}

3 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}