一个字串筛选问题 本帖最后由 ruiman 于 2014-02-08 11:04:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $str="content";preg_match_all("#<a\s*[\n|\r]\s*href=.*?target=\"_blank\">.*?</a>#is", $str, $matches);print_r($matches); $str="content";preg_match_all("#<a\s*[\n|\r]\s*href=.*?\s*[\n|\r]\s*target=\"_blank\">.*?</a>#i", $str, $matches);print_r($matches); $s =<<< TXTdocument.write('<DIV style="margin-bottom: 10px;"><A href="http://news.baidu.com/" target="_blank"><IMG width="60" height="21" align="absbottom" src="Other%20web_files/slogo-news.gif" border="0"></A> <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">教育新闻</A></DIV><DIV class="baidu" style="width: 100%; text-align: left; table-layout: fixed; -ms-word-wrap: break-word;"><A href="http://news.ycwb.com/2014-02/08/content_6034510.htm" target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A> <SPAN>金羊网 06:29</SPAN><BR><A href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm" target="_blank">北京推一本高招计划 定向投放生态涵养区 </A> <SPAN>新华网 09:11</SPAN><BR><A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm" target="_blank">肇庆:主要景区迎客221万人次</A> <SPAN>光明网 08:29</SPAN><BR><A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm" target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A> <SPAN>新华网 08:47</SPAN><BR><A href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm" target="_blank">促进高校毕业生就业有哪些新的改革举措 </A> <SPAN>新华网 10:18</SPAN><BR><A href="http://learning.sohu.com/20140208/n394601900.shtml" target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A> <SPAN>搜狐 09:55</SPAN><BR><A href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍 严禁到中小学招生 </A> <SPAN>新华网山东频道 08:03</SPAN><BR><A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html" target="_blank">西汉“学术超男”策划“诗经秀”取功名</A> <SPAN>人民网 07:04</SPAN><BR><A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html" target="_blank">李鸿章哥哥摆架子被下级痛骂</A> <SPAN>人民网 07:04</SPAN><BR><A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html" target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A> <SPAN>中国教育新闻网 08:50</SPAN><BR><DIV style="font-size: 12px; margin-top: 5px;"><A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">更多>></A></DIV></DIV>');TXT;//全部 A 标记preg_match_all('#<a.+</a>#isU', $s, $r);print_r($r[0]);//仅文字标题的 A 标记preg_match_all('#<a[^<]+</a>#isU', $s, $r);print_r($r[0]);//仅包含指定词汇的 A 标记preg_match_all('#<a[^<]+院士.*</a>#isU', $s, $r);print_r($r[0]);Array( [0] => <A href="http://news.baidu.com/" target="_blank"><IMG width="60" height="21" align="absbottom" src="Other%20web_files/slogo-news.gif" border="0"></A> [1] => <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">教育新闻</A> [2] => <A href="http://news.ycwb.com/2014-02/08/content_6034510.htm" target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A> [3] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm" target="_blank">北京推一本高招计划 定向投放生态涵养区 </A> [4] => <A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm" target="_blank">肇庆:主要景区迎客221万人次</A> [5] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm" target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A> [6] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm" target="_blank">促进高校毕业生就业有哪些新的改革举措 </A> [7] => <A href="http://learning.sohu.com/20140208/n394601900.shtml" target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A> [8] => <A href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍 严禁到中小学招生 </A> [9] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html" target="_blank">西汉“学术超男”策划“诗经秀”取功名</A> [10] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html" target="_blank">李鸿章哥哥摆架子被下级痛骂</A> [11] => <A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html" target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A> [12] => <A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">更多>></A>)Array( [0] => <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">教育新闻</A> [1] => <A href="http://news.ycwb.com/2014-02/08/content_6034510.htm" target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A> [2] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm" target="_blank">北京推一本高招计划 定向投放生态涵养区 </A> [3] => <A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm" target="_blank">肇庆:主要景区迎客221万人次</A> [4] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm" target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A> [5] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm" target="_blank">促进高校毕业生就业有哪些新的改革举措 </A> [6] => <A href="http://learning.sohu.com/20140208/n394601900.shtml" target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A> [7] => <A href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍 严禁到中小学招生 </A> [8] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html" target="_blank">西汉“学术超男”策划“诗经秀”取功名</A> [9] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html" target="_blank">李鸿章哥哥摆架子被下级痛骂</A> [10] => <A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html" target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A> [11] => <A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1" target="_blank">更多>></A>)Array( [0] => <A href="http://news.ycwb.com/2014-02/08/content_6034510.htm" target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A>) 谷歌的查询面页要怎么获取 关于PHP文件及编码的问题 求救 为什么有的数据能插入,有的数据不能?好奇怪的问题 PHP中调用sqlite3的方法名 php5.2.6命令行连接mssql提示错误 “猜数字”游戏 为什么MYSQL会发生这个错误? 在php中,如何像asp一样打开一个新页面? Apache 1.3.14 for win32那里有下载的? session问题 PHP怎么让用户一段时间内只能触发一次程序(发帖时间限制)
preg_match_all("#<a\s*[\n|\r]\s*href=.*?target=\"_blank\">.*?</a>#is", $str, $matches);
print_r($matches);
preg_match_all("#<a\s*[\n|\r]\s*href=.*?\s*[\n|\r]\s*target=\"_blank\">.*?</a>#i", $str, $matches);
print_r($matches);
document.write('
<DIV style="margin-bottom: 10px;"><A href="http://news.baidu.com/" target="_blank"><IMG
width="60" height="21" align="absbottom" src="Other%20web_files/slogo-news.gif"
border="0"></A> <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">教育新闻</A></DIV>
<DIV class="baidu" style="width: 100%; text-align: left; table-layout: fixed; -ms-word-wrap: break-word;"><A
href="http://news.ycwb.com/2014-02/08/content_6034510.htm"
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A> <SPAN>金羊网 06:29</SPAN><BR><A
href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm"
target="_blank">北京推一本高招计划 定向投放生态涵养区 </A> <SPAN>新华网 09:11</SPAN><BR><A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm"
target="_blank">肇庆:主要景区迎客221万人次</A> <SPAN>光明网 08:29</SPAN><BR><A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm"
target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A> <SPAN>新华网 08:47</SPAN><BR><A
href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm"
target="_blank">促进高校毕业生就业有哪些新的改革举措 </A> <SPAN>新华网 10:18</SPAN><BR><A href="http://learning.sohu.com/20140208/n394601900.shtml"
target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A> <SPAN>搜狐 09:55</SPAN><BR><A
href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍
严禁到中小学招生 </A> <SPAN>新华网山东频道 08:03</SPAN><BR><A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html"
target="_blank">西汉“学术超男”策划“诗经秀”取功名</A> <SPAN>人民网 07:04</SPAN><BR><A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html"
target="_blank">李鸿章哥哥摆架子被下级痛骂</A> <SPAN>人民网 07:04</SPAN><BR><A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html"
target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A> <SPAN>中国教育新闻网 08:50</SPAN><BR>
<DIV style="font-size: 12px; margin-top: 5px;"><A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">更多>></A></DIV></DIV>');
TXT;//全部 A 标记
preg_match_all('#<a.+</a>#isU', $s, $r);
print_r($r[0]);//仅文字标题的 A 标记
preg_match_all('#<a[^<]+</a>#isU', $s, $r);
print_r($r[0]);//仅包含指定词汇的 A 标记
preg_match_all('#<a[^<]+院士.*</a>#isU', $s, $r);
print_r($r[0]);Array
(
[0] => <A href="http://news.baidu.com/" target="_blank"><IMG
width="60" height="21" align="absbottom" src="Other%20web_files/slogo-news.gif"
border="0"></A>
[1] => <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">教育新闻</A>
[2] => <A
href="http://news.ycwb.com/2014-02/08/content_6034510.htm"
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A>
[3] => <A
href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm"
target="_blank">北京推一本高招计划 定向投放生态涵养区 </A>
[4] => <A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm"
target="_blank">肇庆:主要景区迎客221万人次</A>
[5] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm"
target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A>
[6] => <A
href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm"
target="_blank">促进高校毕业生就业有哪些新的改革举措 </A>
[7] => <A href="http://learning.sohu.com/20140208/n394601900.shtml"
target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A>
[8] => <A
href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍
严禁到中小学招生 </A>
[9] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html"
target="_blank">西汉“学术超男”策划“诗经秀”取功名</A>
[10] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html"
target="_blank">李鸿章哥哥摆架子被下级痛骂</A>
[11] => <A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html"
target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A>
[12] => <A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">更多>></A>
)
Array
(
[0] => <A class="blk" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">教育新闻</A>
[1] => <A
href="http://news.ycwb.com/2014-02/08/content_6034510.htm"
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A>
[2] => <A
href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm"
target="_blank">北京推一本高招计划 定向投放生态涵养区 </A>
[3] => <A href="http://news.gmw.cn/newspaper/2014-02/08/content_2849438.htm"
target="_blank">肇庆:主要景区迎客221万人次</A>
[4] => <A href="http://news.xinhuanet.com/edu/2014-02/08/c_126098505.htm"
target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 </A>
[5] => <A
href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm"
target="_blank">促进高校毕业生就业有哪些新的改革举措 </A>
[6] => <A href="http://learning.sohu.com/20140208/n394601900.shtml"
target="_blank">借力“适应性学习” Knewton演绎在线教育变革</A>
[7] => <A
href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍
严禁到中小学招生 </A>
[8] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295188.html"
target="_blank">西汉“学术超男”策划“诗经秀”取功名</A>
[9] => <A href="http://edu.people.com.cn/n/2014/0208/c1053-24295191.html"
target="_blank">李鸿章哥哥摆架子被下级痛骂</A>
[10] => <A href="http://www.jyb.cn/basc/xw/201402/t20140208_569160.html"
target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉</A>
[11] => <A class="more" href="http://news.baidu.com/n?cmd=1&class=edunews&pn=1"
target="_blank">更多>></A>
)
Array
(
[0] => <A
href="http://news.ycwb.com/2014-02/08/content_6034510.htm"
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 </A>
)