pauleth Posted May 22, 2008 Share Posted May 22, 2008 Hey folks, I am trying to write a regular expression that will remove any html formating from a body of text and just leave the text in place. For example: <p><img src="img.jpg" alt="">This is the text that I want.</p> Will become, This is the text that I want. Does anyone have any suggestions on how I can accomplish this with regular expressions? I figure that I need to write an expression with ereg_replace() that removes the html brackets, '<' and '>', and also removes any text between the brackets... Thanks in advance for your suggestions. Quote Link to comment https://forums.phpfreaks.com/topic/106763-solved-regular-expressions-question/ Share on other sites More sharing options...
mlin Posted May 22, 2008 Share Posted May 22, 2008 strip_tags does exactly that...use that otherwise if you want more control...use kses (kses kills evil scripts) ask google, kses has good documentation and is really easy to use. Quote Link to comment https://forums.phpfreaks.com/topic/106763-solved-regular-expressions-question/#findComment-547294 Share on other sites More sharing options...
jonsjava Posted May 22, 2008 Share Posted May 22, 2008 <?php $code = "<p><img src='img.jpg' alt=''>This is te text that I want.</p>"; $stripped = strip_tags($code); print $stripped; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106763-solved-regular-expressions-question/#findComment-547295 Share on other sites More sharing options...
pauleth Posted May 22, 2008 Author Share Posted May 22, 2008 You guys are the best! That worked perfectly. Thank you!!!! Quote Link to comment https://forums.phpfreaks.com/topic/106763-solved-regular-expressions-question/#findComment-547308 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.