我有我根据自己的“年龄”(最后两天)聚集了几个文件,我现在需要遵循正规表达式模式(在这种情况下,从中提取文字,图案是像微软的产品密钥),这是我到目前为止已经完成:PHP正则表达式匹配
<?php
$files = iterator_to_array(
new GlobIterator('/var/www/log/access.log.*', GlobIterator::CURRENT_AS_PATHNAME));
foreach ($files as $file) {
$filelastmodified = filemtime($file);
if((time()-$filelastmodified) < 48*3600 && is_file($file))
{
$regexp = '/^[A-Z1-9]{5}(-[A-Z1-9]{5}){4}$/';
preg_match_all($regexp, file($file), $keys, PREG_PATTERN_ORDER);
}
}
print_r($keys, true);
?>
但我发现了一个错误:
PHP Warning: preg_match_all() expects parameter 2 to be string, array given in /var/www/log/keys.php on line 11
我在做什么错? 此外,我想知道是否有可能保存唯一匹配的文本字符串,这意味着如果一个键出现两次,我只需要它一次保存到数组中。 在此先感谢
[PHP.net文件手册](http://php.net/manual/en/function.file.php)'数组文件(字符串$ filename [,int $ flags = 0 [,resource $ context]])'返回数组。由于**期望参数2是字符串**,这是不正确的。 – xdbas
错误消息告诉你到底发生了什么问题。你没看过吗? – Sylverdrag