一个字串筛选问题
PHP 字符串 正则表达式
才在学习PHP,现在遇到一个$contents变量里面的内容如下 document.write('
border="0"> target="_blank">教育新闻
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 金羊网 06:29
href="http://news.xinhuanet.com/edu/2014-02/08/c_126099001.htm"
target="_blank">北京推一本高招计划 定向投放生态涵养区 新华网 09:11
target="_blank">肇庆:主要景区迎客221万人次 光明网 08:29
target="_blank">把对故乡眷恋藏心里 春节后娃娃随父母出发 组图 新华网 08:47
href="http://news.xinhuanet.com/edu/2014-02/08/c_119240720.htm"
target="_blank">促进高校毕业生就业有哪些新的改革举措 新华网 10:18
target="_blank">借力“适应性学习” Knewton演绎在线教育变革 搜狐 09:55
href="http://www.sd.xinhuanet.com/news/2014-02/08/c_119235535.htm" target="_blank">山东为自费留学中介上紧箍
严禁到中小学招生 新华网山东频道 08:03
target="_blank">西汉“学术超男”策划“诗经秀”取功名 人民网 07:04
target="_blank">李鸿章哥哥摆架子被下级痛骂 人民网 07:04
target="_blank">江苏金坛教育系统工作“贴地行走”摸准基层脉 中国教育新闻网 08:50
现在想把里面的这样的内容 href="http://news.ycwb.com/2014-02/08/content_6034510.htm"
target="_blank">川大教授张兴栋当选美国国家工程院外籍院士 筛几条出来,请问应如何操作。
回复讨论(解决方案)
"筛几条" 是指哪几条?这个标准怎么定义?
$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 src="/static/imghw/default1.png" data-src="Other%20web_files/slogo-news.gif" class="lazy" style="max-width:90%" style="max-width:90%" align="absbottom" border="0" alt="一个字串筛选问题" ></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 src="/static/imghw/default1.png" data-src="Other%20web_files/slogo-news.gif" class="lazy" style="max-width:90%" style="max-width:90%" align="absbottom" border="0" alt="一个字串筛选问题" ></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>)
感谢版主的回答,正则表达式也看过,没想到能这么用,完全解决了我的问题,知道我的需求,大师就是大师哦

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio
