I have a string in which I want to highlight word “some”:
$my_string = "This is some string.";
$highlight = "some";
And I need to wrap this word in <span> tags using some php function which can suit this job the best.
I am using this for my simple search on my website.
So, I would like the end result looks like this:
This is <span class="highlight-word">some</span> string.
You can use
str_replaceas mentioned in comments. So, in your case, it’d look like this: