Encode-intercept Chinese-remove HTML characters

Source: Internet
Author: User
Tags ord

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/&GT;&LT;?PHPHeader(' content-type:text/html; Charset=utf-8 ');functionContent_replace ($show _content){     $search=Array(        "' <script[^>]*?>.*?</script> ' si ',//Filter Script Tags"' <iframe[^>]*?>.*?</iframe> ' si ',//Filter IFRAME Tags"' <style[^>]*?>.*?</style> ' si ',//Filter Style Tags"' <[\/\!] *span[^<>]*?> ' Si ',//filtering span Markers"' <[\/\!] *strong[^<>]*?> ' Si ',         "' <[\/\!] *span[^<]*?> ' Si ',//filtering span Markers"' <[\/\!] *br[^<>]*?> ' Si ',//Filter BR Mark"' <[\/\!] *img[^<>]*?> ' Si ',//filtering img Tags"' <[\/\!] *input[^<>]*?> ' Si ',//Filter Input Tags"' <[\/\!] *font[^<>]*?> ' Si ',//Filter Font Tags"' <[\/\!] *textarea[^<>]*?> ' Si ',//Filter TextArea marks"' <[\/\!] *form[^<>]*?> ' Si ',//Filter Form Tags"' <[\/\!] *a[^<>]*?> ' Si ',//filter a tag, if you want to filter the word in the link, you must write it down in the filter rule. "' <[\/\!] *div[^<>]*?> ' Si ',//Filter div Tags"' <[\/\!] *tbody[^<>]*?> ' Si ',//Filter Table Tags"' <[\/\!] *table[^<>]*?> ' Si ',//Filter Table Tags"' <[\/\!] *tr[^<>]*?> ' Si ',//Filter Table Tags"' <[\/\!] *td[^<>]*?> ' Si ',//Filter Table Tags"' <[\/\!] *p[^<>]*?> ' Si ',//Filter P Mark"' <[\/\!] *o:p[^<>]*?> ' Si ',//Filter O:p marks"' <[\?\!] *xml:[^<>]*?> ' Si ',//Filter xml: Tags"' <[\/\!] *select[^<>]*?> ' Si ',//Filter Select Tags"' <[\/\!] *option[^<>]*?> ' Si ',//Filter Option Tag"' <[\/\!] *v:[^<>]*?> ' Si ',//Filter V: Mark"' <[\/\!] *o:[^<>]*?> ' Si ',//filter O: Mark"' Target= ([^\s>]*) |method= ([^\s>]*) |action= ([^\s>]*] |rows= ([^\s>]*) |cols= ([^\s>]*] |type= ([^\s >]*) |href= ([^\s>]*) |src= ([^\s>]*] |id= ([^\s>]*) |class= ([^\s>]*) |name= ([^\s>]*] |align= ([^\s >]*) |cellpadding= ([^\s>]*) |cellspacing= ([^\s>]*) |border= ([^\s>]*] |bordercolor= ([^\s>]*) | Background= ([^\s>]*) |bgcolor= ([^\s>]*) ' Si ",        "' (\d+); ' E ",    ); $replace=Array(",", "," "," "," "," ",", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Chr (\\1)"); $show _content=Preg_replace($search,$replace,$show _content); $show _content=Preg_replace("/style=[" \ "]* ([^ ' \"]*) [' \ ']*/is ', "",$show _content); $show _content=Str_replace("\ r \ n", "",$show _content);//Remove line breaks in HTML &nbsp;$show _content=Str_replace("<span", "",$show _content);//Remove line breaks in HTML &nbsp;$show _content=Str_replace("&nbsp;", "",$show _content);//Remove line breaks in HTML$show _content=Str_replace(" ", "",$show _content);//Remove line breaks in HTMLreturn $show _content; }//Chinese character intercept functionfunctionCNSUBSTR ($string,$sublen,$a=0){    if($string= = "'){        return false; }    $string= Changeyinhaocom ($string, ' Out '); $sum= 0;  for($i= 0;$i<strlen($string) ;$i++){        if(Ord($string{$i}) > 127) {            $s.=$string{$i} .$string{++$i} .$string{++$i}; $sum++; Continue; } Else {            $s.=$string{$i}; $sum++; Continue; }    }    if($sublen>=$sum) {        return $string; }    $s= ""; $index= 0;  for($i= 0;$i<$sublen;$i++) {        if(Ord($string{$index}) > 127) {            $s.=$string{$index} .$string{++$index} .$string{++$index}; $index++; Continue; } Else {            $s.=$string{$index}; $index++; Continue; }    }    if($a===0){        $s.="..."; }Else{        $s.=$a; }    return $s;}functionChangeyinhaocom ($content,$flag){    if($flag= = "in"){        $content=Str_replace("\" "," &quot; ",$content); $content=Str_replace("'", "& #39;",$content); }    if($flag= = "Out"){        $content=Str_replace("&quot;", "\" ",$content); $content=Str_replace("& #39;", "'",$content); }    return $content;}//Calling Methods$str= ' This is a long string I'm going to intercept it ';EchoCnsubstr (Content_replace ($str), 5);Echo $res;

Encode-intercept Chinese-remove HTML characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.