Determine if a string contains hyperlinks
| The code is as follows |
|
|
$str = "SSDSFSDFSDFSS";
if (Preg_match ("/]*>| ]*>/i ", $str))
{
echo "The string has a hyperlink";
}
Else
{
echo "The string does not have a hyperlink tag";
}
?> |
Let's just filter the connection section below.
| The code is as follows |
|
|
echo Preg_replace ("/(? <=href=) ([^>]*) (?=>)/I", "#", "Hello, click here to see Hello, click here to see");
?> |
Regular:/(? <=href=) ([^>]*) (?=>)/
(? <=exp) matches the position after exp
(? =exp) matches the position of the exp front
This regular matches all characters that are not ">" before ">" After href=
Example:
Find these characters (URLs) and replace them with # to get rid of all the links in the HTML.
Now share an instance of extracting a super connection
| The code is as follows |
|
|
function Match_links ($document) {
Preg_match_all ("' ]+)" [^>]*>? (.*?)' Isx ", $document, $links);
while (list ($key, $val) = each ($links [2])) {
if (!empty ($val))
$match [' link '] [] = $val;
}
while (list ($key, $val) = each ($links [3])) {
if (!empty ($val))
$match [' link '] [] = $val;
}
while (list ($key, $val) = each ($links [4])) {
if (!empty ($val))
$match [' content '] = $val;
}
while (list ($key, $val) = each ($links [0])) {
if (!empty ($val))
$match [' All '] [] = $val;
}
return $match;
} |
http://www.bkjia.com/PHPjc/372042.html www.bkjia.com true http://www.bkjia.com/PHPjc/372042.html techarticle determine if a string contains the hyperlink code as follows $str =SSDSFA target= ' _blank ' href= ' http://www.45it.net/' SDF/ASDFSS; if (Preg_match (/a/s+href =[^]*|//[^a]*a[^]*/i, $str)) {...