【发布时间】:2014-10-09 03:37:51
【问题描述】:
我想获取这些链接标签中的文本:
<a target="_blank" class="timestamp" href="http://www.link.com/1">10:55 am</a>
<a target="_blank" class="timestamp" href="http://www.link.com/2">3:30 pm</a>
到目前为止,我有:
preg_match_all('/<a (.*?)<\/a>/s', $html, $matches);
print_r($matches[1]);
不幸的是,它返回两个 a 之间的所有内容。有没有办法只获取 a 标记之间的文本,表示上午 10:55 和下午 3:30,仅此而已?
【问题讨论】:
-
一个非常粗糙的正则表达式:
<a[^>]*>(.*?)<\/a> -
确实不起作用并不是对它为什么不起作用的描述。好吧,这是一个proof,它确实有效。
标签: php regex regex-negation