1,字符串的转义操作vs取消转义
form表里面提交的字符串将一些字符,比如\',",\等自动添加\转义成为\\',\",\\,可以使用函数
string stripslashes ( string str )
与此相反,添加转义\字符,可以使用string addslashes ( string str )
2,显示html和js代码vs执行代码
有些用户添加一些js代码,然而我们不希望他们执行,仅仅让他们显示,可以使用函数
string htmlentities ( string string [, int quote_style [, string charset]] )
string htmlspecialchars ( string string [, int quote_style [, string charset]] )
作用如下:
\'&\' (ampersand) becomes \'&\'
\'"\' (double quote) becomes \'"\' when ENT_NOQUOTES is not set.
\'\'\' (single quote) becomes \'\'\' only when ENT_QUOTES is set.
\'<\' (less than) becomes \'<\'
\'>\' (greater than) becomes \'>\'
如果要执行,可以执行相反的函数,如下
string html_entity_decode ( string string [, int quote_style [, string charset]] )
form表里面提交的字符串将一些字符,比如\',",\等自动添加\转义成为\\',\",\\,可以使用函数
string stripslashes ( string str )
与此相反,添加转义\字符,可以使用string addslashes ( string str )
2,显示html和js代码vs执行代码
有些用户添加一些js代码,然而我们不希望他们执行,仅仅让他们显示,可以使用函数
string htmlentities ( string string [, int quote_style [, string charset]] )
string htmlspecialchars ( string string [, int quote_style [, string charset]] )
作用如下:
\'&\' (ampersand) becomes \'&\'
\'"\' (double quote) becomes \'"\' when ENT_NOQUOTES is not set.
\'\'\' (single quote) becomes \'\'\' only when ENT_QUOTES is set.
\'<\' (less than) becomes \'<\'
\'>\' (greater than) becomes \'>\'
如果要执行,可以执行相反的函数,如下
string html_entity_decode ( string string [, int quote_style [, string charset]] )