I have the following code in a WordPress theme functions.php. I'm using PHP 7.1 both locally and remotely.
if ( ! function_exists( 'highlight_search_results' ) ) :
// this filter runs on the_excerpt and the_title
// to highlight inside both locations for search result pages
add_filter( 'the_excerpt', 'highlight_search_results' );
add_filter( 'the_title', 'highlight_search_results' );
function highlight_search_results( $text ) {
if ( is_search() && ! is_admin() ) {
$sr = get_query_var( 's' );
$highlighted = preg_filter( '/' . preg_quote( $sr ) . '/i', '<span class="a-search-highlight">$0</span>', $text );
if ( ! empty( $highlighted ) ) {
$text = $highlighted;
}
}
return $text;
}
endif;
It worked nicely in development, with no errors, until deployment to our server. It functions to highlight the user's search term in the WordPress search results page, both in the title and in the excerpt of the post. However I don't think my issue is necessarily WordPress related.
On our live server, it results in this recurring PHP error:
[php7:warn] PHP Warning: preg_filter(): Unknown modifier 'k' in /wp-content/themes/minnpost-largo/inc/extras.php on line 209
What can I ask my host to look for? Alternatively, is there another way I should more reliably achieve this goal?