澳门新葡亰娱乐官网PHP利用str

*———————- 过滤HTML代码的函数 ———————–*/
function htmlEncode($string) { $string=trim($string);
$string=str_replace(,,$string); $string=str_replace(”,”,$string);
$string=str_replace(amp;,,$string);
$string=str_replace(quot;,,$string); $string=str_replace(,,$string);
$string=str_replace(lt;,,$string); $string=str_replace(,,$string);
$string=str_replace(gt;,,$string); $string=str_replace(,,$string);
$string=str_replace(nbsp;, ,$string); $string=nl2br($string); return
$string; }

PHP各个过滤字符函数
复制代码 代码如下:
       /**
    * 安全过滤函数
    *
    * @param $string
    * @return string
    */
    function safe_replace($string) {
    $string = str_replace(‘%20’,”,$string);
    $string = str_replace(‘%27’,”,$string);
    $string = str_replace(‘%2527’,”,$string);
    $string = str_replace(‘*’,”,$string);
    $string = str_replace(‘”‘,'”‘,$string);
    $string = str_replace(“‘”,”,$string);
    $string = str_replace(‘”‘,”,$string);
    $string = str_replace(‘;’,”,$string);
    $string = str_replace(‘    $string =
str_replace(‘>’,’>’,$string);
    $string = str_replace(“{“,”,$string);
    $string = str_replace(‘}’,”,$string);
    $string = str_replace(”,”,$string);
    return $string;
    }
    ?>

        /**
    * 重回经addslashes管理过的字符串或数组
    * @param $string 须求管理的字符串或数组
    * @return mixed
    */
    function new_addslashes($string) {
    if(!is_array($string)) return addslashes($string);
    foreach($string as $key => $val) $string[$key] =
new_addslashes($val);
    return $string;
    }
    ?>

康宁过滤函数,用于过滤惊险字符 

        //对诉求的字符串进行安全管理
    /*
    $safestep
    0 为不管理,
    1 为制止不安全HTML内容(javascript等卡塔尔,
    2
通通禁止HTML内容,并替换部份不安全字符串(如:eval(、union、CONCAT(、–、等)
    */
    function StringSafe($str, $safestep=-1){
    $safestep = ($safestep > -1) ? $safestep : 1;
    if($safestep == 1){
    $str = preg_replace(“#script:#i”, “script:”, $str);
    $str = preg_replace(“#]*>#isU”, ”, $str);
    $str = preg_replace(“#[ ]{1,}#”, ‘ ‘, $str);
    return $str;
    }else if($safestep == 2){
    $str = addslashes(htmlspecialchars(stripslashes($str)));
    $str = preg_replace(“#eval#i”, ‘eval’, $str);
    $str = preg_replace(“#union#i”, ‘union’, $str);
    $str = preg_replace(“#concat#i”, ‘concat’, $str);
    $str = preg_replace(“#–#”, ‘--’, $str);
    $str = preg_replace(“#[ ]{1,}#”, ‘ ‘, $str);
    return $str;
    }else{
    return $str;
    }
    }
    ?>

function safe_replace($string) {
 $string = str_replace(‘ ‘,”,$string);
 $string = str_replace(”’,”,$string);
 $string = str_replace(”’,”,$string);
 $string = str_replace(‘*’,”,$string);
 $string = str_replace(‘”‘,'”‘,$string);
 $string = str_replace(“‘”,”,$string);
 $string = str_replace(‘”‘,”,$string);
 $string = str_replace(‘;’,”,$string);
 $string = str_replace(‘<‘,'<‘,$string);
 $string = str_replace(‘>’,’>’,$string);
 $string = str_replace(“{“,”,$string);
 $string = str_replace(‘}’,”,$string);
 return $string;
}

   

       /**
        +———————————————————-
        * 输出安全的html,用于过滤危险代码
        +———————————————————-
        * @access public
        +———————————————————-
        * @param string $text 要拍卖的字符串
        * @param mixed $tags 允许的价签列表,如 table|td|th|td
        +———————————————————-
        * @return string
        +———————————————————-
        */
       static public function safeHtml($text, $tags = null)
       {
           $text =  trim($text);
           //完全过滤注释
           $text = preg_replace(‘//’,”,$text);
           //完全过滤动态代码
           $text =  preg_replace(‘/|?’.’>/’,”,$text);
           //完全过滤js
           $text = preg_replace(‘/

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图