求一正则表达式, 多谢

WBOY
Release: 2016-06-13 11:19:12
Original
776 people have browsed it

求一正则表达式, 谢谢

本帖最后由 phpisshow 于 2013-03-29 15:23:27 编辑
<br /><body><br /><br /><a href="/news/news-list.php?id=5">标题名称</a><br /><br /><a <br />href="<br />/news/news-list.php?id=6">标题名称</a><br /><br /><a class="bds_qzone"></a> <a class="bds_tsina"></a> <a class="bds_tqq"></a> <a href="/news/news-list.php?id=7">标题名称</a><br /><br /></body><br />
Copy after login



匹配页面中所有带有href链接的A标签,不带href的不需要,

需要提出三个参数, 1, 标题名称这一整段 2,/news/news-list.php?id=5链接地址 3,标题名称

我之前这样的
<br />preg_match_all('/<a(?:[\s\S]*?)href\s*?=\s*?[\'"](((?:http(?:s?):\/\/)?([^\"\'\/]+))?(?:[^\"\']*))[\'"](?:[^>]*?)>([\s\S]*?)<\/a>/i'<br />
Copy after login

但第三种没有href的就一直匹配下去了。把整个没带href的A标签也匹配进去了.但这又不是贪婪匹配

求个能解决的正则啊啊,谢谢各位了


------解决方案--------------------
$s=<<<br /><body><br /><br /><a href="/news/news-list.php?id=5">标题名称</a><br /><br /><a <br />href="<br />/news/news-list.php?id=6">标题名称</a><br /><br /><a class="bds_qzone"></a> <a class="bds_tsina"></a> <a class="bds_tqq"></a> <a href="/news/news-list.php?id=7">标题名称</a><br /><br /></body><br />html;
preg_match_all('/]+href="(.+)"[^>]*>(.+)<\/a>/isU',$s,$m);
print_r($m);
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!