Pluda
Pluda

Reputation: 1477

php clean html regex

Well, I always have many dificulties with regex or regular expressions, so I'm asking help with this.

I'm trying to explore the html editing capabilities of browser, but most times I got things I don't need, like this one

<div style="text-align: left;"><span style="font-size: small;"><font face="verdana"><br></font></span></div>

Can someone be so nice to provide me a regex to transform this into just <br> ?

the ideal deal was if possible to have one dealing with diferent combinations like font face could be other than verdana and the style for text-align could be center per example.

Thanks in advance.

Pluda

Upvotes: 0

Views: 501

Answers (2)

mario
mario

Reputation: 145512

If you want to remove a fixed accumulation of HTML soup with a simple br tag, then a regex could be workable. I don't see the difficulty here however. Your string contains no meta characters itself. So you only have to replace left and Verdana with placeholders like \w+ or [\w\s]+ and put everything into delimiters like #.

Upvotes: 0

Jason McCreary
Jason McCreary

Reputation: 73031

Regular expressions are not the right path due to their limitations for parsing HTML.

I think you'd be better off looking into strip_tags(). Particularly using the second parameter on which tags to allow. However, determining which tags to remove and keep may be difficult in your case. You may want to update your question if this is indeed the case.

Upvotes: 1

Related Questions