根据php手册和discz论坛里的代码总结出来的类。各位看着用,很好用。
毕竟封装起来再调用是一个很好的习惯。
不好意思,没有分了哈
[修改后工作正常的类]
/*
- class slash is used to add or strip slashes in the post,get or cookies strings.
- method:strip ,to strip
- method:add,to add.
/
class slash{
/
- function strip is to strip the tag in the post ,get or cookies
- which was added by the system or by add function
*/
function strip()
{
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
}
/*
- add is to add slashes to post or get or cookie string,if the magic_quotes_gpc is set as 0,this
- function will worked.
*/
function add()
{
if (!get_magic_quotes_gpc()) {
$this->add_Slashes(&$_POST);
$this->add_Slashes(&$_GET);
}
}
function add_Slashes($pText) {
if ( is_array($pText) && count($pText) ) {
foreach ($pText as $pKey -> $pVal) {
$pText[$pKey] = $this->add_Slashes($pVal);
}
} else {
$pText=$this->addslashes($pText);
}
return $pText;
}
}