Hello,
My knowledge of regular expressions is pretty limited; and I have to get something done very soon using them. I have a variable called $searchString. I've searched for strings in a database which have text that matches that provided string. I'd like to add <span class="highlight"> before the search string and close the span right after.
Right now I have:
preg_replace("|($searchWord)|Ui" , "<span class=\"highlight\">$searchString</span>" , $string);
So, if the user searches for pAnTs, they will see:
"I like to wear <span class="highlight>pAnTs</span> all day" instead of "I like to wear <span class="highlight>pants</span> all day", which is the exact string in the database with the proper cases.
I want to simply replace the beginning and end of the search string with the highlight class, instead of all of it so that it looks exactly like it does in the database.
Any help would be much appreciated. Sorry if this is a complete noob question (but unfortunately, I kind of am one).