fork download
  1. <?php
  2.  
  3. $html = '
  4. <div style="height:100px;" id="main" >
  5. <div style = height:100px; id="main" >
  6. <a href="133"></a>
  7. <blockquote color="123"/>
  8. <a class = asdfsdf href="http://n...content-available-to-author-only...t.com/.[some stuff to find].zip">
  9. <a href=\'http://n...content-available-to-author-only...t.com/.[more stuff to find].zip \'>
  10. <a hello world href = http://n...content-available-to-author-only...t.com/.[unquoted_stuff_to_find].zip />
  11. <a>
  12. ';
  13.  
  14. $regex = '~
  15. ( < (?:div|span|a|img|ul|li|blockquote) (?=\s) ) # 1
  16. (?=
  17. (?:
  18. (?:[^>"\']|"[^"]*"|\'[^\']*\')*?
  19. ( # 2
  20. \s style \s*=
  21. (?: (?> \s* ([\'"]) \s* (?:(?!\g{-1}) .)* \s* \g{-1} ) #3
  22. | (?> (?!\s*[\'"]) \s* [^\s>]* (?=\s|>) )
  23. )
  24. )
  25. )?
  26. )
  27. \s* (?:".*?"|\'.*?\'|[^>]*?)+
  28. ( /?> ) # 4
  29. ~xs';
  30.  
  31. echo preg_replace( $regex, '$1$2$4', $html);
  32.  
  33. ?>
  34.  
Success #stdin #stdout 0.02s 13256KB
stdin
Standard input is empty
stdout
<div style="height:100px;">
<div style = height:100px;>
<a></a>
<blockquote/>
  <a>
  <a>
  <a/>
<a>