PHP 批量删除网页内容中超级链接
在做内容站时,经常会用到采集软件在互联网上大肆侵略别站的资源,一采集就是几千篇的文章,采集之后 发现内容中有些原站点的超级链接,要是一个个去改的话 很麻烦 所以写了个方法,测试成功。
简单说一下原理,这里重利用的是 PHP 的替换函数 preg_replace,在实际应用中,我们经常使用 preg_replace 去替换一些危险字符或去转换一些斜杠或回车等。preg_replace($1,$2,$3) 有三个重要的参数,其中 $1 是要搜索的字符串,$2 是要替换成的字符串,$3 是要进行替换的字符串。
那么知道了 preg_replace 函数工作的原理,那么进行替换超链接就不难了,我们只需要将参数 $1 和 $2 转换成数组,进行批量替换,以下是方法,测试成功,共享给 phper 。
代码如下 | 复制代码 |
$str="超级链接|这是个链接 |
或
代码如下 | 复制代码 |
$content = file_get_contents('test.html'); $url = 'http://www.hzhuti.com'; //要换成的新网址 $preg = '/[s]href=("|')[S]*("|')/i'; $replace = ' href="' . $url . '"'; $content = preg_replace($preg, $replace, $content); //正则替换 create_log('newhtml', $content); //生成新文件 ?> |
都是可以的

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 Linux new version
SublimeText3 Linux latest version

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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
