There is such a section of HTML, more irregular, if you want to extract the link address and link name, how to do?
Html
$str = '<a id="top8" href="http://list.MP3.baidu.com/song/A.htm?top8" class="p14" target="_top">歌曲列表</a><br><a target="_blank" id="bp" href="http://list.mp3.baidu.com/list/bangping.html" class="p14">中文金曲榜</a><br><td nowrap="nowrap">• <a id="top19" href="qingyinyue.html?top19" class="p14" target="_top">轻音乐</a></td>';
The use of regular expressions is the simplest, the other way, even rice to think ...
$pat = '/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/i';
preg_match_all($pat, $str, $m);
Output method:
print_r($m[2]);
print_r($m[4]);
Or:
for($i=0;$i<count($m[2]) ;$i++ ){
echo '<li><a href="'.$_SERVER['PHP_SELF'].'?url='.$m[2][$i].'">'.$m[4][$i].'</a>';
}
The results displayed 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] => 歌曲列表 [1] => 中文金曲榜 [2] => 轻音乐 )
So, we want to collect a website title and link address method came out. Apply it yourself.