1

After a couple of hours I'm really desperated. I have a database dump with tons of inlinestyles and deprecated html-tags.

What would be the regex to get this espression?

style="margin: 0cm 0cm 0pt;mso-layout-grid-align: none" class="MsoNormal">

That means I would like to get. 1. start with the word style 2. grab everything in the middle 3. stop with the closing bracket

Ronny Linsener
  • 253
  • 3
  • 16
  • possible duplicate of [RegEx match open tags except XHTML self-contained tags](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – Mureinik Jan 16 '15 at 09:17

2 Answers2

2

Try this: preg_replace('/style="[^>]+>/',"",$string)

Ahosan Karim Asik
  • 3,219
  • 1
  • 18
  • 27
  • Works perfect and saves me a lot of time. Thanks a lot. – Ronny Linsener Jan 16 '15 at 09:36
  • this is not better way. because, some content is missing... i think your problem is quotation problem.. before insert into db you can use `mysql_real_escape_string` this function for content to clean. or u can googling by `quotation problem in database..` – Ahosan Karim Asik Jan 16 '15 at 09:45
  • @Ronny Linsener check update. right way to use is `preg_replace('/style="[^>]+>/',"",$string)` and `preg_replace('style="[^>]+>',"",$string)` is not right way.. – Ahosan Karim Asik Jan 16 '15 at 10:07
0

how about this?

preg_match('#style=".+?"\s*>#');
yunzen
  • 32,854
  • 11
  • 73
  • 106