PHP matches the method of link address in character, match link address _php tutorial

Source: Internet
Author: User
Tags php programming

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 ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.