由于我对正则表达式完全无能为力,这已经困扰了我半个小时,我想我会把它发布在这里,因为它可能非常简单。
<a href="/folder/files/hey/">hey.exe</a>
<a href="/folder/files/hey2/">hey2.dll</a>
<a href="/folder/files/pomp/">pomp.jpg</a>
在PHP中,我需要提取位于
<a>
标签之间的内容,例如:hey.exe
hey2.dll
pomp.jpg
由于我对正则表达式完全无能为力,这已经困扰了我半个小时,我想我会把它发布在这里,因为它可能非常简单。
<a href="/folder/files/hey/">hey.exe</a>
<a href="/folder/files/hey2/">hey2.dll</a>
<a href="/folder/files/pomp/">pomp.jpg</a>
<a>
标签之间的内容,例如:hey.exe
hey2.dll
pomp.jpg
'/<a[^>]+>([^<]+)<\/a>/i'
preg_match_all($pattern, $string, $matches);
// matches get stored in '$matches' variable as an array
// matches in between the <a></a> tags will be in $matches[1]
print_r($matches);
这是一个非常简单的例子:
<a.*>(.*)</a>
<a href="/folder/hey">hey.exe</a><a href="/folder/hey2/">hey2.dll</a>
<a.*?>(.*?)</a>
这似乎可以工作:
$pattern = '/<a.*?>(.*?)<\/a>/';
<a href="[^"]*">([^<]*)</a>