How to set HTML value attribute (with spaces)

后端 未结 5 995
日久生厌
日久生厌 2020-11-27 08:08

When I use PHP to set the value of a HTML form input element, it works fine provided I don\'t have any spaces in the data.



        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 08:34

    Quote it. Otherwise the space will just become an attribute separator and everything after spaces will be seen as element attributes. Rightclick page in webbrowser and view source. It should not look like this (also see syntax highlight colors):

    
    

    but rather this

    
    

    Not to mention that this would still break when someone has a quote in his name (and your code is thus sensitive to XSS attacks). Use htmlspecialchars().

    Kickoff example:

    
    

提交回复
热议问题