PHP Regular Expression Extract hyperlink and its caption, Regular expression Hyperlink _php tutorial

Source: Internet
Author: User
Tags php regular expression

PHP Regular Expression Extract hyperlink and its caption, Regular expression hyperlink


There is such a piece of HTML, more irregular, if you want to extract the link address and link name, how to do?

Html
$str = ' song list
Chinese Melody List
• Light Music ";

Using regular expressions is the simplest, and the other way, even rice to think ...

$pat = "/(. *?) <\/a>/i ";
Preg_match_all ($pat, $str, $m);

Output method:

Print_r ($m [2]);
Print_r ($m [4]);

Or:
for ($i =0; $i
Echo '

  • ". $m [4][$i].";
    }

    The display results are:

    Array ([0] = HTTP://LIST.MP3.BAIDU.COM/SONG/A.HTM?TOP8 [1] = http://list.mp3.baidu.com/list/bangping.html [2] = = qingyinyue.html?top19) Array ([0] = song list [1] = [2] = light music)

    So, we want to collect a website title and link address method came out ... Apply it yourself ...

    Reprinted from: http://www.aspnetjia.com

    http://www.bkjia.com/PHPjc/1096602.html www.bkjia.com true http://www.bkjia.com/PHPjc/1096602.html techarticle The PHP Regular expression extracts the hyperlink and its caption, the regular expression hyperlink has such a piece of HTML, compares the irregular, if wants to extract the link address and the link name in it, how to get? ...

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