Determine if a string contains hyperlinks
| The code is as follows |
|
|
$str = "Ssdsf<a target= ' _blank ' href= ' http://www.45it.net/' >SDF</A>SDFSS '";
if (Preg_match ("/<a/s+href=[^>]*>|<//[^a]*a[^>]*>/i", $str))
{
echo "This string has a hyperlink";
}
Else
{
echo "This string has no hyperlink tag";
}
?> |
Now we just need to filter the connection part.
| The code is as follows |
|
|
<?php
echo preg_replace ("/<=href=) ([^>]*) (?=>)/I", "#", "<a href= ' www.45it.net ' > Hello, click here to see </a><a href= ' www.45it.net ' > Hello, click here to see </a> ');
?> |
Regular:/(? <=href=) ([^>]*) (?=>)/
(? <=exp) matches the position of the exp rear
(? =exp) match the position of the exp front
This matches all characters that are not ">" before ">" After href=
Example: <a href= ' www.45it.net ' >
Find these characters (URLs) with the # replacement, you can remove all the links in HTML.
Now share an instance of extracting a super connection
| code is as follows |
&nbs P; |
| Function Match_links ($document) {
& nbsp; preg_match_all ("' <s*as.*?hrefs*=s*")? (1) (.*?) 1| ([^s>]+)] [^>]*>? (.*?) </a> ' Isx ', $document, $links); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP
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 ($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
} |