Home > Backend Development > PHP Tutorial > 求一正则表达式, 谢谢

求一正则表达式, 谢谢

WBOY
Release: 2016-06-23 14:04:12
Original
907 people have browsed it

<body><a href="/news/news-list.php?id=5">标题名称</a><a href="/news/news-list.php?id=6">标题名称</a><a class="bds_qzone"></a> <a class="bds_tsina"></a> <a class="bds_tqq"></a> <a href="/news/news-list.php?id=7">标题名称</a></body>
Copy after login



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

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

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

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

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


回复讨论(解决方案)

$s=<<]+href="(.+)"[^>]*>(.+)<\/a>/isU',$s,$m);print_r($m);
Copy after login

PHP code?12345678910111213141516$s= 标题名称 标题名称  ……

好了,谢谢,虽然你没区分单引号和双引号,感谢.

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