PHP matches the method of the link address in the word, matching the link address
The example in this paper describes the method of linking addresses in PHP matching characters. Share to everyone for your reference. Specific as follows:
To determine if a string contains hyperlinks, the code is as follows:
Copy the Code code 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";
}
?>
Below we just filter the connection section, the code is as follows:
Copy the Code code as follows: <?php
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) with # Replace, you can remove all the links in the HTML, now share an extract Super connection instance, the code is as follows:
Copy the Code code 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 is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/931548.html www.bkjia.com true http://www.bkjia.com/PHPjc/931548.html techarticle PHP matches the method of the link address in the word, matching the link address in this paper, we describe the method of matching the link address in PHP. Share to everyone for your reference. Specific as follows: Judge a ...