PHP strip odd html tag
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&u=1&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
GarySince 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.
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.
Here is a perfect example where a regex won't cut it (at least one that isn't convoluted).
Use a DOM parser.
精彩评论