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/imghwm/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/imghwm/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>)
感谢版主的回答,正则表达式也看过,没想到能这么用,完全解决了我的问题,知道我的需求,大师就是大师哦

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-

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.

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' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

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

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...


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

SublimeText3 Chinese version
Chinese version, very easy to use

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),