Home >Backend Development >PHP Tutorial >How to match link addresses in php characters, match link addresses_PHP tutorial

How to match link addresses in php characters, match link addresses_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:06883browse

php method of matching link addresses in characters, matching link addresses

The example in this article describes the method of matching link addresses in characters in PHP. Share it with everyone for your reference. The details are as follows:

To determine whether a string contains a hyperlink, the code is as follows:

Copy code The code is as follows:

Next we only need to filter the connection part, the code is as follows:
Copy code The code is as follows:

Regular: /(?<=href=)([^>]*)(?=>)/

(?<=exp) matches the position after exp

(?=exp) matches the position before exp

This regex matches all characters that are not “>” after href= and before “>”

Example: , find these characters (url) and replace them with #, you can remove all links in the html. Now share an example of extracting super links, the code is as follows :

Copy code The code is as follows:
function match_links($document) { 
preg_match_all("']+))[^>] *>?(.*?)
'isx",$document,$links); While(list($key,$val) = each($links[2])) {
If(!emptyempty($val))
                $match['link'][] = $val;
}
While(list($key,$val) = each($links[3])) {
If(!emptyempty($val))
                $match['link'][] = $val;
                                             While(list($key,$val) = each($links[4])) {
If(!emptyempty($val))
                 $match['content'][] = $val;
}
While(list($key,$val) = each($links[0])) {
If(!emptyempty($val))
                $match['all'][] = $val;
                                                                         Return $match;
}


I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/931548.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/931548.htmlTechArticleHow to match link addresses in php characters, match link addresses. This example describes how to match link addresses in php characters. . Share it with everyone for your reference. The details are as follows: Judgment 1...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn