Match multiple terms within <body> tags
        Posted  
        
            by Jeepstone
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jeepstone
        
        
        
        Published on 2010-04-07T08:06:23Z
        Indexed on 
            2010/04/07
            8:23 UTC
        
        
        Read the original article
        Hit count: 242
        
I've want to match any occurrence of a search term (or list of search terms) within the tags of a document. My current solution uses preg (within a Joomla plugin)
$pattern = '/matchthisterm/i';
$article->text = preg_replace($pattern,"<span class=\"highlight\">\\0</span>",$article->text);
But this replaces everything within the HTML of the document so I need to match the tags first. Is this even the best way to achieve this?
© Stack Overflow or respective owner