spaze Posted January 15, 2010 Share Posted January 15, 2010 Hello all! I am writing a class where you set a string to be searched and a keyword to search. I have written so far: $replacement = '<' . $this->_htmlTag . ' class="' . $this->_htmlClass . '">' . $keyword . '</' . $this->_htmlTag . '>'; $result = preg_replace("/(>|^)([^<]+)(?=<|$)/iesx","'\\1' . str_replace('" . $keyword . "', '" . $replacement . "', '\\2')", $entry); This works fine as long as the search is case sensitive, It wraps found instances if they are not inside HTML tags. I can't seem to figure out how to make case insensitive replacement and I knwo why. It's because I wrap the search keywords with html tags and not the found instances, so can someone please show me how to complete this code to replace the found instances instead of using the str_replace? Quote Link to comment https://forums.phpfreaks.com/topic/188562-highlight-class-for-search-keywords-within-html-string/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.