0

I have a user input form where the user is allowed to use HTML, such as div, span, etc.

I would like to clean the input only if a user happens to put in a div with a style="width:" that is over the site width (which in this case is 800px.)

So I wanted to do a preg_replace searching for div style="width:" only when width is greater than 800px.

I already have all other fixes in place for spans, div width="", etc. but the preg_replace on the div style="width:" where the width is only changed if it is greater than 800 (such as 1500px, 2000px, 801px) eludes me - I cannot get it to work.

Is there any way to achieve this?

gpoo
  • 8,408
  • 3
  • 38
  • 53

1 Answers1

1

The pony he comes...

How would you go about handling something like width:140%? Or width: 600px; margin: 200px;? Or just an image with no defined width but an intrinsic width of over 800px?

It's far easier to just put the user-supplied content in a wrapper:

<div style="width: 800px; overflow: hidden;">USER CONTENT HERE</div>
Community
  • 1
  • 1
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Yes, I think I was overthinking it - the overflow:hidden didn't even cross my mind. It is the best fix. Thank you. – user1751361 Oct 16 '12 at 22:01