【发布时间】:2016-05-04 04:18:58
【问题描述】:
我可以使用下面的preg_match_all() 函数计算匹配链接的数量,该函数检查链接的内部文本是否等于指定的关键字。
// text contains two different links, whereby the inner
// text of the first link is capitalized and the second link starts with a small letter.
$string = "<p><a href=\"www.link1.com\" class=\"someClass\" title=\"lorem\">Lorem</a> dolor sit amet, consectetur
adipiscing elit. In iaculis, libero aliquam lacinia feugiat, <a href=\"www.link2.com\" class=\"someClass\" title=\"lorem\">lorem</a>
elit congue risus, sed sagittis turpis tortor eget orci. Integer lacinia quis nisi ac aliquet. Sed et convallis diam.</p>";
// count al matches by upper and lowercase sensitivity
preg_match_all('/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>lorem<\/a>/siU', $string, $match);
现在我的问题是如何制作正则表达式,以便它也适用于大写字母的匹配。
【问题讨论】:
-
this question的可能重复