meral Posted August 20, 2009 Share Posted August 20, 2009 I have one string also having html tags... <p>hello</p><b>bold</b><br /><p style="text-align:right">right align</p> i want find all html tags and add space before and after that tag... #<p>#hello#</p>##<b>#bold#</b>##<br />##<p style="text-align:right">#right align#</p># Consider # as white space I think it can be achive through Regular Expression and preg_match but how i dont know... please help .. atleast give some idea.. Quote Link to comment https://forums.phpfreaks.com/topic/171149-find-html-tags-and-replace/ Share on other sites More sharing options...
nrg_alpha Posted August 20, 2009 Share Posted August 20, 2009 Example: $html = '<p>hello</p><b>bold</b><br /><p style="text-align:right">right align</p>'; $html = preg_replace('#<[^>]+>#', ' $0 ', $html); Quote Link to comment https://forums.phpfreaks.com/topic/171149-find-html-tags-and-replace/#findComment-902615 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.