/**
* 转义html字符
*
* @param string|array $var
*/
function fhtmlspecialchars($var) {
if (is_array ( $var )) {
foreach ( $var as $k => $v ) {
$var [$k] = fhtmlspecialchars ( $v );
}
} else if (is_string ( $var )) {
$var = htmlspecialchars ( $var, ENT_COMPAT, 'UTF-8' );
}
return $var;
}
/**
* 过滤html标签.
*
* @param string $var target string
* @param string $tags 允许保留到标签,all 为去全部
*/
function fstripTags($var, $tags = 'all') {
$tags = strval ( $tags );
if ($tags !== 'all') {
if (is_array ( $var )) {
foreach ( $var as $k => $v ) {
$var [$k] = fstripTags ( $v );
}
} else if (is_string ( $var )) {
$var = strip_tags ( $var, $tags );
}
}
return $var;
}
/**
* 获取参数值
* @param string $name http参数key
* @param bool $htmQuotes 是否转义html
* @param string $tags 允许保留到标签,all 为去全部
* @return string | array
*/
public static function get ($name = null, $default =null, $htmQuotes = true, $tags = null) {
if (!$name) return self::$DATA;
if (!isset(self::$DATA[$name])) {
return $default;
}
$str = self::$DATA[$name];
if ($htmQuotes) {
$str = fhtmlspecialchars($str);
}
if ($tags !== 'all') {
$str = fstripTags($str, $tags);
}
return $str;
}