- array_map: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- preg_quote: documentation ( source)
- preg_replace: documentation ( source)
<?php
$source = 'quick, brown" (for example), but not "quick and brown". So whe';
$test = "QUICK BROWN";
$temp = explode(" ", $test);
$temp = array_map(function ($val) { return preg_quote($val, "~");}, $temp);
$pattern = '~('.implode("[^A-Za-z0-9]+", $temp).')~i';
echo preg_replace( $pattern , '<span class="hilite">$1</span>', $source );