Be careful how you do it. HTML highlighting is an output task, not what you want to do with data that you are not going to print directly on the page.
I think that the pages will be fairly explicit in this matter and really separate content filtering from content escaping.
$tags = array_map( 'filterTag', explode( ',', $_GET['tags'] ) );
$tagsSafeForHtml = array_map( 'escapeForHtml', $tags );
function filterTag( $tag )
{
return trim( strip_tags( $value ) );
}
function escapeForHtml( $value )
{
return htmlspecialchars( $value, ENT_COMPAT, 'UTF-8' );
}
source
share