protected function getKeywordsForRegex(array $keywords, $delimiter = '/')
    {
        // escape keywords for use in regex
        $delimiter = array_fill(0, count($keywords), $delimiter);
        $escaped = array_map('preg_quote', $keywords, $delimiter);

        // add word boundaries
        array_walk($keywords, function ($value) {
            return '\b'.$value.'\b';
        });

        $keywords = array_combine($keywords, $escaped);

        return $keywords;
    }
protected function getKeywordsForRegex(array $keywords, $delimiter = '/')
    {
        // escape keywords for use in regex
        $delimiter = array_fill(0, count($keywords), $delimiter);
        $escaped = array_map('preg_quote', $keywords, $delimiter);

        // add word boundaries
        array_walk($keywords, function ($value) {
            return '\b'.$value.'\b';
        });

        $keywords = array_combine($keywords, $escaped);

        return $keywords;
    }
protected function getKeywordsForRegex ( array $ keywords , $ delimiter = '/' ) { // escape keywords for use in regex $ delimiter = array_fill ( 0 , count ( $ keywords ) , $ delimiter ) ; $ escaped = array_map ( 'preg_quote' , $ keywords , $ delimiter ) ; // add word boundaries array_walk ( $ keywords , function ( $ value ) { return '\b' . $ value . '\b' ; } ) ; $ keywords = array_combine ( $ keywords , $ escaped ) ; return $ keywords ; }
We'll strip whitespace around certain keywords with regular expressions.
This will prepare the given array by escaping all characters.

@param string[] $keywords
@param string   $delimiter

@return string[]
We ll strip whitespace around certain keywords with regular expressions . This will prepare the given array by escaping all characters .