tags:

views:

43

answers:

2

Can anybody tell me a regular expression to use within some PHP to find the following:

  1. <p>&nbsp;</p> with any variation of white space between those tags

  2. <p><br/> again with any variation of white space between those tags

Any help appreciated, thanks!

+1  A: 

If you want to parse XML (or HTML) you should think about using a XML parser instead of regex. It would be more efficient.

PHP already contains an XML parser which is good for you :)


Resources :

On the same topic :

Colin Hebert
Hey, thanks. It’s actually for a parameter within an ExpressionEngine find and replace plugin, which I thought would be using PHP.
James
@Colin: XML parser vs. regex isn't necessarily "more efficient" depending on what the task is. It's usually "more correct"; but in this very limited case scenario, regex actually works fine (and possibly faster).
Amber
A: 

Pretty straightforward (and folks, because he's asking for things with only whitespace between them, not nested tags or attributes or any of that, a parser isn't necessary in this case...)

/<p>\s+<\/p>/

/<p>\s+<br\/>/
Amber
Perfect. Thanks!
James