When building a content website, I often use collection software to invade the resources of other sites on the Internet. I collect thousands of articles. After collecting, I find that there are some hyperlinks to the original site in the content. If I go there one by one It would be troublesome to change it, so I wrote a method and the test was successful.
Let’s briefly talk about the principle. What is reused here is PHP’s replacement function preg_replace. In practical applications, we often use preg_replace to replace some dangerous characters or convert some slashes or carriage returns, etc. preg_replace($1,$2,$3) has three important parameters, where $1 is the string to be searched, $2 is the string to be replaced, and $3 is the string to be replaced.
Now that we know how the preg_replace function works, it is not difficult to replace hyperlinks. We only need to convert the parameters $1 and $2 into arrays and perform batch replacement. The following is the method. The test is successful and shared with phper.
The code is as follows
|
Copy code
|
||||
"; function removelink($str){ $mode=array("##iUs","##iUs"); $want=array("",""); $con=preg_replace($mode,$want,$str); return $con; } echo removelink($str); ?>
|
http: //www.bkjia.com/PHPjc/633069.html