本文章详细的总结了php利用正则过滤链接、标签,空格,换行符程序,有需要学习的朋友可参考一下。
strip_tags函数
strip_tags --- 去除字串中的HTML和PHP标签
语法 : string strip_tags (string str [, string allowable_tags])
例
代码如下 | 复制代码 |
$text = ' Test paragraph. Other text';echo strip_tags($text); echo "n"; // Allow |
正则过滤各种标签,空格,换行符
代码如下 | 复制代码 |
$str=preg_replace("/s+/", " ", $str); //过滤多余回车 |
php 正则过滤html 的超链接
代码如下 | 复制代码 |
echo preg_replace("/(?]*)(?=>)/i","#", "你好,点这里看看你好,点这里看看"); ?> |
正则:/(?]*)(?=>)/
(?
(?=exp) 匹配exp前面的位置
此正则 匹配 在 href= 之后 “>” 之前 的 非 “>” 的所有字符
例子:
找到这些字符(url)用 # 替换,就可以去掉html里的所有链接。

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

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

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

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