使用strip_tag或写入列表进行文本输入的原因是什么[复制]

I know they are both use for prevent XSS attack. But when i use htmlspecialchars , it seems just ok. <script> and <?php ?> would be displayed on the screen. It means they are not functioning, right? So, my question is , is htmlspecialchars enough for preventing XSS. If so, what is the reason using strip_tag or a white list of tag?

</div>

htmlspecialchars is safe enough. It is very common as it displays the same as the user typed, but makes it harmless. strip_tags takes all the tags away, is usefull for alot of other things.