I'm creating highlights of the searchwords on the results page.
This is what I use now:
$resmessage = preg_replace ( '/' . preg_quote ( $searchword, '/' ) . "/iu", '<span class="searchword" >' . $searchword . '</span>', $resmessage );
But when the word is an title name on a attachment is will break the layout.
example text:
test ok /n[attachment=1]test-2.png[/attachment]
The result:
test ok test-2.png" title="test-2.png" rel="lightbox[imagelink2]"> test-2.png" style="max-height:800px;" alt="" />
So I want exclude none character before searchword. What is the regex to do that, I have tried many options.
none character? Whitespace?... or what is$searchwordso I can run the test locally.<span class="searchword" >test</span>ok /n[attachment=1]test-2.png[/attachment], is that right?