I have the following html string example. I want to add tags around the naked text:
$html='<span>text1</span> text2 <a href="yahoo.com">yeahoo</a> text4 <div>abc</div> xyz';
assuming correctly formatted html I would like to add a tag (E.g. ) around text2, text4 and xyz.
I envision a simple function that is called: $resHtml=addTagsToNakedText($html,'<span>','</span>');
The net result should be:
'<span>text1</span><span> text2 </span><a href="yahoo.com">yeahoo</a><span> text4 </span><div>abc</div><span> xyz</span>'
Any ideas how to do this? I assume this needs some regular expression capabilities.
Thanks
Credit goes to:
Obligatory answer link: stackoverflow.com/questions/1732348/… – SimpleCoder yesterday
Thanks