preg_match到数组。 PHP

时间:2010-11-27 15:00:37

标签: php string preg-match

调用所有PHP助手。

所以基本上我想给函数preg_match一个可以包含几千行代码的变量,并让它在widlcard的任一侧使用通配符+字符串进行搜索。

例如,我想搜索看起来像<a href="*.pdf">

的字符串

我希望函数返回一个数组中的每个匹配(以及通配符周围的html shiz,这也是为了捕获任何目录结构),我可以使用foreach(){}循环来循环。 / p>

我猜这是可能的,有人有时间帮我这个吗?

我检查了所有的preg_match lit'并通过这里的答案,但我似乎无法使模式正确。提前谢谢。

和平了。

1 个答案:

答案 0 :(得分:4)

unset($matches);
preg_match_all('/<a href="[^"]+\.pdf">/',$text,$matches);
foreach ($matches as $match)
{
    $shiz = $match[0];
    // Your code here ...
}