spaze Posted August 20, 2009 Share Posted August 20, 2009 I have an application to convert some HTML pages to work better on my ebook reader device. I need to replace two things: All leading and trailing spaces between opening and closing tags. Example: <p> blaa blaa</p> The other thing is I need to remove all <p></p> tags containg some number, can be with spaces or without and with line breaks. Examples: <p> 1</p> <p> 1</p> <p> 1 </p> Can someone help me with this issue as I don't seem to get it Quote Link to comment https://forums.phpfreaks.com/topic/171197-how-to-replace-these-things-in-html-code/ Share on other sites More sharing options...
Daniel0 Posted August 20, 2009 Share Posted August 20, 2009 $string = preg_replace('#<p>\s*(.*?)\s*</p>#i', '<p>$1</p>', $string); $string = preg_replace('#<p>\d+</p>#', '', $string); Quote Link to comment https://forums.phpfreaks.com/topic/171197-how-to-replace-these-things-in-html-code/#findComment-902820 Share on other sites More sharing options...
spaze Posted August 20, 2009 Author Share Posted August 20, 2009 The first one works just fine, but the second one doesn't do much for the following line: <p> 9</p> It doesn't replace it with an empty one at all. Quote Link to comment https://forums.phpfreaks.com/topic/171197-how-to-replace-these-things-in-html-code/#findComment-902877 Share on other sites More sharing options...
Daniel0 Posted August 20, 2009 Share Posted August 20, 2009 It will if you run them after each other. The first one makes already makes sure that <p> 9</p> will not exist anywhere, but it will be <p>9</p>. Quote Link to comment https://forums.phpfreaks.com/topic/171197-how-to-replace-these-things-in-html-code/#findComment-902882 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.