Forum Moderators: not2easy

Message Too Old, No Replies

An attribute inside a </div> tag

Just wondering how kosher this is...

         

dataguy

12:00 pm on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a block of HTML code on some pages of my site that needs to be stripped before being displayed to certain visitors. The entire page source is stored in a variable and then echoed after it has been completely processed.

The easiest way to do this is to put the code in between div tags and then filter out everything from the start to the finish of this div.

The problem is that there are sometimes divs within this div, so when I look for the ending </div> sometimes the function stops on one of the divs in the code.

I'm wondering if it is acceptable to create a custom closing div tag, like '</div id="endCode">'. I've never heard of this before and I can't find any documentation on doing this.

Thanks for your help.

mattur

12:51 pm on May 31, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could do, but it wouldn't be valid HTML and you would be relying on browsers' error recovery routines to not screw up the page. So IMHO it's not an acceptable solution.

Attributes, id's and classes apply to the element, not the individual opening and closing tag(s), and are always declared on the opening tag. Closing tags never do or specify anything except the closing of the element.

If you need an identifier for the final closing </div> in your code, you could just use e.g. </div*> and just make sure you strip the asterisk before display in each scenario.

Or, probably better, you could use a html comment like <!-- endCode --></div>, and not have to worry about sanitising it before display.

dataguy

7:03 pm on Jun 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks mattur, I took your advice and it's working perfectly. Not sure why it wasn't obvious to me in the first place.