求 匹配多個a標籤串連和名字 Regex
比如這樣的源碼
HTML code
知識 維普資訊 中國期刊網 龍源期刊網 郵政報刊訂閱網 雜誌鋪 MBA智庫百科 星空天文網 勸學網
牧夫天文論壇 專利之家 環球科學 科學松鼠會 UFO探索網 果殼網 我學網 網易公開課
維基百科 我要自學網 中國留學網 知乎 網易學院 搜搜問問 新手學上網 國家核安全域
word聯盟 愛問知識人 中國文明網
唉 說來都不好意思,
前不久問了這個問題 ,但是當時是只有一個a標籤時,有很多好心人幫我解決了。http://topic.csdn.net/u/20111216/16/934599d3-8e99-4b94-8dae-28e5b9c455c4.html
但是,現在是多個A標籤時,我怎麼改都是出錯。
還請高手指點一下。我應該怎麼弄一下。
------解決方案--------------------
PHP code
preg_match_all('/(.*)$href) { $arr[$matches[2][$k]] = $href;}var_export($arr);/**輸出結果:array ( '維普資訊' => 'http://www.cqvip.com/', '中國期刊網' => 'http://www.chinaqking.com/', '龍源期刊網' => 'http://www.qikan.com.cn/', '郵政報刊訂閱網' => 'http://bk.183.com.cn/index.do', '雜誌鋪' => 'http://www.zazhipu.com/', 'MBA智庫百科' => 'http://wiki.mbalib.com/', '星空天文網' => 'http://www.cosmoscape.com/', '勸學網' => 'http://www.quanxue.cn/', '牧夫天文論壇' => 'http://www.astronomy.com.cn/bbs/', '專利之家' => 'http://www.patent-cn.com/', '環球科學' => 'http://www.sciam.com.cn/', '科學松鼠會' => 'http://songshuhui.net/', 'UFO探索網' => 'http://www.ufo-1.cn/', '果殼網' => 'http://www.guokr.com/', '我學網' => 'http://www.5xue.com/', '網易公開課' => 'http://v.163.com/open/', '維基百科' => 'http://zh.wikipedia.org/', '我要自學網' => 'http://www.51zxw.net/', '中國留學網' => 'http://www.cscse.edu.cn/', '知乎' => 'http://www.zhihu.com/', '網易學院' => 'http://tech.163.com/school/video/', '搜搜問問' => 'http://wenwen.soso.com/', '新手學上網' => 'http://xue.baidu.com/', '國家核安全域' => 'http://nnsa.mep.gov.cn/', 'word聯盟' => 'http://www.wordlm.com/', '愛問知識人' => 'http://iask.sina.com.cn/', '中國文明網' => 'http://www.wenming.cn/', )//PS:一次達到,好像沒啥方法。*/
------解決方案--------------------
PHP code
知識 維普資訊 中國期刊網 龍源期刊網 郵政報刊訂閱網 雜誌鋪 MBA智庫百科 星空天文網 勸學網
牧夫天文論壇 專利之家 環球科學 科學松鼠會 UFO探索網 果殼網 我學網 網易公開課
維基百科 我要自學網 中國留學網 知乎 網易學院 搜搜問問 新手學上網 國家核安全域
word聯盟 愛問知識人 中國文明網 ';$patten = '/(.*)<\/a>/iU';preg_match_all($patten,$str,$match);$result = array();for($i = 0;$i";print_r($result);?>