php转义和去掉html、php标签函数
/**
?* 轉(zhuǎn)義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標(biāo)簽.
?*
?* @param string $var target string
?* @param string $tags 允許保留到標(biāo)簽,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;
}
?
/**
???? * 獲取參數(shù)值
???? * @param string $name http參數(shù)key
???? * @param bool $htmQuotes 是否轉(zhuǎn)義html
???? * @param string $tags 允許保留到標(biāo)簽,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;
??? }
轉(zhuǎn)載于:https://www.cnblogs.com/andydao/p/3208800.html
總結(jié)
以上是生活随笔為你收集整理的php转义和去掉html、php标签函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Openssl 之大数运算函数 BN
- 下一篇: shell的date