I would like such empty span tags (filled with and space) to be removed:
<span> </span>
I've tried with this regex, but it needs adjusting:
(<span>( |\s)*</span>)
preg_replace('#<span>( |\s)*</span>#si','<\\1>',$encoded);
Translating Kent Fredric's regexp to PHP :
preg_match_all('#<span[^>]*(?:/>|>(?:\s| )*</span>)#im', $html, $result);
This will match :
Maybe you should about including spans containings only <br /> as well...
As usual, when it comes to tweak regexp, some tools are handy :
http://regex.larsolavtorvik.com/
.
qr{<span[^>]*(/>|>\s*?</span>)}
Should get the gist of them. ( Including XML style-self closing tags ie: )
But you really shouldn't use regex for HTML processing.
Answer only relevant to the context of the question that was visible before the formatting errors were corrected
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With