search
Homephp教程php手册php 过滤所有html标签

php 过滤所有html标签

Jun 13, 2016 am 10:11 AM
filterhtmlphpstringremoveusrecommendLabelfilterfilterfirst

首先我们推荐filter_sanitize_string ,filter_sanitize_string 过滤器去除或编码不需要的字符。

这个过滤器删除那些对应用程序有潜在危害的数据。它用于去除标签以及删除或编码不需要的字符。

name: "string"
id-number: 513
可能的选项或标志:

filter_flag_no_encode_quotes - 该标志不编码引号
filter_flag_strip_low - 去除 ascii 值在 32 以下的字符
filter_flag_strip_high - 去除 ascii 值在 32 以上的字符
filter_flag_encode_low - 编码 ascii 值在 32 以下的字符
filter_flag_encode_high - 编码 ascii 值在 32 以上的字符
filter_flag_encode_amp - 把 & 字符编码为 &

*/

$var="bill gates";

var_dump(filter_var($var, filter_sanitize_string));

/*
第二个函数strip_tags
strip_tags() 函数剥去 html、xml 以及 php教程 的标签。

语法
strip_tags(string,allow)
*/

echo strip_tags("hello world!");

//hello world!

function uh($str)
{
    $farr = array(
        "/s+/",                                                                    
                       //过滤多余的空白
        "/]*?)>/isu",
  //过滤 <script></script> 以加入         "/(]*)on[a-za-z]+s*=([^>]*>)/isu",                                     
//过滤网页特效的on事件
     
   );
   $tarr = array(
        " ",
        "<123>",           //如果要直接清除不安全的标签,这里可以留空
        "12",
   );

  $str = preg_replace( $farr,$tarr,$str);
   return $str;
}

更多详细内容请查看:http://www.bKjia.c0m/phper/19/70dd2a905e74cefc9be9c0f17268dadc.htm
?>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft