当前位置:Gxlcms > PHP教程 > 求婚配多个a标签连接和名字正则表达式

求婚配多个a标签连接和名字正则表达式

时间:2021-07-01 10:21:17 帮助过:7人阅读

求 匹配多个a标签连接和名字 正则表达式
本帖最后由 xiachao2008 于 2011-12-19 16:04:25 编辑

比如这样的源码

知识 维普资讯 中国期刊网 龙源期刊网 邮政报刊订阅网 杂志铺 MBA智库百科 星空天文网 劝学网
 牧夫天文论坛 专利之家 环球科学 科学松鼠会 UFO探索网 果壳网 我学网 网易公开课
 维基百科 我要自学网 中国留学网 知乎 网易学院 搜搜问问 新手学上网 国家核安全局
 word联盟 爱问知识人 中国文明网


唉 说来都不好意思,

前不久问了这个问题 ,但是当时是只有一个a标签时,有很多好心人帮我解决了。http://topic.csdn.net/u/20111216/16/934599d3-8e99-4b94-8dae-28e5b9c455c4.html
但是,现在是多个A标签时,我怎么改都是出错。
还请高手指点一下。我应该怎么弄一下。


------解决方案--------------------
preg_match_all('/(.*)
foreach($matches[1] as $k=>$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/', )

人气教程排行