Php matches the link address in the character. Php matching character link address method. This article describes how to match the link address in php matching characters. Share it with you for your reference. The specific method is as follows: to determine a php matching character link address, match the link address
This article describes how to match the link address in php characters. Share it with you for your reference. The details are as follows:
To determine whether a string contains a hyperlink, the code is as follows:
The code is as follows:
$ Str = "ssdsfsdfsdfss ";
If (preg_match ("/] *> | ] *>/I ", $ str ))
{
Echo "this string has a hyperlink ";
}
Else
{
Echo "this string has no hyperlink mark ";
}
?>
Below we only need to filter the connection part, the code is as follows:
The code is as follows:
<? Php
Echo preg_replace ("/(? <= Href =) ([^>] *) (? =>)/I "," # "," Hello, click here to see you, click here to see ");
?>
Regular :/(? <= Href =) ([^>] *) (? => )/
(? <= Exp) match the position behind exp
(? = Exp) match the position before exp
This regular expression matches all non-">" characters before ">" after href =
Example: find these characters (URLs) and replace them with # to remove all links in html. now we share an instance that extracts Super connections. the code is as follows:
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 help you with PHP programming.
Examples in this article describes how php matches the link address in characters. Share it with you for your reference. Details: Judge 1...