In HTML5, under certain circumstances, some closing tags are optional. If you leave those closing tags out, the W3C validator will not point them out, since they are technically not an error. Some people, though, may want to close all their tags anyway.
This scripts assumes that the code submitted is valid, otherwise, you could get unexpected results.