strip_tags — 从字符串中去除 HTML 和 PHP 标记
说明
strip_tags ( string
$str
[, string $allowable_tags
] ) : string该函数尝试返回给定的字符串 str
去除空字符、HTML 和 PHP 标记后的结果。它使用与函数 fgetss() 一样的机制去除标记。
参数
str
-
输入字符串。
allowable_tags
-
使用可选的第二个参数指定不被去除的字符列表。
Note:
HTML 注释和 PHP 标签也会被去除。这里是硬编码处理的,所以无法通过
allowable_tags
参数进行改变。Note:
In PHP 5.3.4 and later, self-closing XHTML tags are ignored and only non-self-closing tags should be used in
allowable_tags
. For example, to allow both <br> and <br/>, you should use:<?php
strip_tags($input, '<br>');
?>
返回值
返回处理后的字符串。 php知识网