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