有这么一段HTML,比较不规则的,如果要提取其中的链接地址和链接名称,怎么弄?
以下为引用的内容: //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>’; |
利用正则表达式是最简单的,其它的办法,偶米去想。。。
以下为引用的内容: $pat = ‘/<a(.*?)href="(.*?)"(.*?)>(.*?)</a>/i’; preg_match_all($pat, $str, $m); |
输出方法:
以下为引用的内容: print_r($m[2]); print_r($m[4]); |
或者:
以下为引用的内容: for($i=0;$i<count($m[2]) ;$i++ ){ echo ‘<li><a href="’.$_SERVER[‘PHP_SELF’].’?url=’.$m[2][$i].’">’.$m[4][$i].'</a>’; } |
显示结果是:
以下为引用的内容: 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] => 轻音乐 ) |
于是,我们要采集某个网站的标题及链接地址方法就出来了。。。自己套用吧。。。
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » PHP正则表达式提取超链接及其标题
波比源码 » PHP正则表达式提取超链接及其标题
cheap levaquin levaquin cost
order avodart online cheap order ondansetron pills buy zofran 4mg without prescription
spironolactone generic valacyclovir price buy diflucan 100mg
ampicillin 500mg pill cephalexin 250mg drug erythromycin 500mg drug
buy sildenafil pills nolvadex 20mg us buy methocarbamol 500mg generic
buy sildenafil 100mg generic cost aurogra estradiol 2mg drug
tadalis online buy voltaren 50mg drug diclofenac 50mg canada
order generic isotretinoin cheap amoxil 1000mg azithromycin price
brand indomethacin buy cefixime for sale amoxicillin pills
arimidex 1mg generic arimidex 1 mg ca viagra sale
buy deltasone 20mg for sale viagra 100mg without prescription sildenafil pharmacy
cialis 5mg kaufen ohne rezept viagra 200mg kaufen sildenafil für männer
order accutane 40mg for sale buy stromectol 6mg generic ivermectin 3mg tab
cost provigil 100mg Discount cialis no rx diamox 250 mg without prescription
doxycycline 100mg ca buy clomid 50mg online furosemide over the counter
purchase buspirone sale purchase buspar online cheap oxybutynin 2.5mg generic
terazosin 5mg over the counter buy pioglitazone 15mg sulfasalazine 500mg for sale
isosorbide 20mg drug imdur canada telmisartan 80mg uk
order molnunat 200mg online cefdinir 300mg for sale buy lansoprazole 30mg for sale
zoloft tablet Buy cheap viagra online us sildenafil online buy
order cialis 5mg without prescription order generic fluoxetine buy viagra 50mg for sale
cost avlosulfon purchase allegra without prescription cheap perindopril 4mg
provigil 100mg cheap modafinil 200mg canada generic stromectol for humans
purchase fluvoxamine sale glucotrol 5mg cost glipizide 5mg uk
order isotretinoin 10mg online cost prednisone order generic prednisone 10mg
cialis 20mg sale buy sildenafil 100mg for sale buy sildenafil 50mg online cheap
furosemide oral lasix pill buy generic plaquenil 200mg
buy tadalafil 20mg for sale female cialis anafranil pill
order amlodipine 10mg for sale cialis tadalafil 10mg generic tadalafil
purchase zyvox brand linezolid 600 mg play roulette online real money
prilosec generic blackjack free cash poker online
purchase lopressor sale purchase atenolol order levitra 20mg online
oral clomid clomid 100mg usa gambling site
triamcinolone pill oral desloratadine buy generic clarinex 5mg
dapoxetine tablet priligy generic buy synthroid generic
cialis cost buy viagra generic order viagra 100mg for sale
purchase orlistat sale acyclovir ca cost acyclovir
order allopurinol online cheap zetia 10mg without prescription zetia 10mg tablet
order generic losartan 50mg nexium 20mg oral topiramate 100mg pill
buy baclofen 10mg for sale buy ozobax brand toradol 10mg
order imitrex 25mg online order dutasteride sale buy dutasteride pill
casino slots free real money slots poker online best
cheap tamsulosin 0.2mg purchase flomax online cheap buy generic spironolactone 100mg
cost tadalafil canadian cialis order cipro
order zocor 20mg buy zocor 20mg pills order propecia
cephalexin 125mg usa cleocin oral order erythromycin 500mg generic
buy ceftin 250mg purchase ceftin online buy methocarbamol online cheap
black jack card game free tadalafil 40mg uk overnight delivery cialis
viagra for women cheap tadalafil sale buy tadalafil 5mg
doubleu casino provigil sale purchase modafinil pill