0


I am facing a problem when I use strip_tags to convent HTML to text.
The html code is

<img style="max-width: 60px; max-height: 90px;
            width: expression(this.width > 60 ? 60: true);
            height: expression(this.height > 90 ? 90: true);"
     src="image.php?s=d377256dd97b17e9bf0b1182743c95c2&amp;u=1&amp;dateline=1215813557"
     alt="DailyFX Forum Administrator's Avatar" />

the strip_tags can't work well, I want write some code using preg_replace, but I don't how to match the last >, not the > in the style . Can you help me ?

Thanks
Gary

deceze
  • 510,633
  • 85
  • 743
  • 889
Gary Li
  • 401
  • 5
  • 12
  • 1
    Unrelated: this is a very strange expression: `height: expression(this.height > 90 ? 90: true);` Now possible: `height: true;`?? Do you mean: `height: expression(this.height > 90 ? 90: this.height);` If you do, just use `max-height: 90px;` – Rudie May 01 '11 at 02:14
  • @Rudie I think this CSS expression was made to get around IE6's limitations (such as no support for `max-height` property). – alex May 01 '11 at 02:29
  • IE6? What the hell is IE6? If you use IE6, you deserve crappy, unreadable websites that fail and break and destroy your computer. – Rudie May 01 '11 at 02:37
  • 1
    Stackoverflow has code highlighting. Indent your code by 4 spaces (or select it and press the `{}` button). That'll mark your code as code. There's no need to HTML-escape everything. – deceze May 01 '11 at 02:40
  • @Rudie Fair enough, you must be lucky enough to not have to support it. – alex May 02 '11 at 00:23
  • @alex Nobody **has** to support it. I've chosen not to. Same for IE7. I mean this: if you use IE < 8, you don't deserve websites. And that's your own (or your organization's) fault. – Rudie May 02 '11 at 09:32
  • @Rudie So having a percentage of your visitors have an untested experience OK with you? – alex May 02 '11 at 10:28
  • @alex Yes. I don't care what my websites/apps do on your browser if you're running IE6 or 7. As long as you do, you're slowing down internet innovation. But that's another discussion. IE6 FTW! – Rudie May 02 '11 at 11:17

3 Answers3

1

Since your markup is invalid you must sanitize it before using strip_tags or any other markup parser. For this specific issue, you can try: preg_replace("expression([^)]+)", "", $your_html)

I recommend you switch to using a stylesheet instead of inline styles so you have valid markup.

Magicianeer
  • 2,190
  • 1
  • 15
  • 12
  • Yes .There is not short cut .It is only way to sanitize it before use strip_tags. Such as preg_replace(array(''/]*>.*?<\/style>/mi'), "", $your_html) – Gary Li May 02 '11 at 14:26
0

Here is a perfect example where a regex won't cut it (at least one that isn't convoluted).

Use a DOM parser.

alex
  • 479,566
  • 201
  • 878
  • 984
0

You really don't want to try to parse complicated HTML with a preg_replace. It's nearly impossible to get right.

Take a look at http://simplehtmldom.sourceforge.net/ or one of the other PHP HTML libraries.

Community
  • 1
  • 1
Eli
  • 5,500
  • 1
  • 29
  • 27