php实现过滤表单提交中html标签的方法
有时候我们做的简单评论功能会发现有提交很多的html标签,这些标签会导致页面有一些外连的情况,下面我们一起来看在php中过滤表单提交的html标签方法。
近评论中有一些机器人提交的post链接,都是一些垃圾评论。为了减少这种无谓的链接内容出现,其实是可以用php来删除表单POST提交的html标签,这样机器提交的信息也不会得到他们要的结果。而且可以减少来自seo/seo.html" target="_blank">搜索引擎的惩罚。
这里以去掉
标签为例:
某些情况我们需要去掉
标签,可以使用str_replace函数。
代码如下:
//取出br标记
$str=str_replace("
","",$str);
移除html标签:
可以使用strip_tags函数搞定。
复制代码 代码如下:
$str= strip_tags($str);
封装成一个函数:
代码如下:
function removehtml($str){
$str=str_replace("
","",$str);
return strip_tags($str);
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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),

SublimeText3 English version
Recommended: Win version, supports code prompts!

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 Linux new version
SublimeText3 Linux latest version