我正在使用foreach和preg_match收集一些数据,如果preg_math为true,它将把该元素添加到数组$find中,但返回此错误:
PHP警告:array_push()要求参数1为数组,字符串在upfiles.PHP第324行中给出
$found = array();
foreach($this->disFunctions as $kkeys => $vvals)
{
if(preg_match('#'.$vvals.'#i', $cFile))
{
array_push($found, $vvals); // LINE 324
} else {
$found = '';
}
} // end foreach
print_r($found);
编辑:
将array_push值放入我的类:
public final function filterFile(){
$disabled_functions = ini_get('disable_functions');
$disFunctionsNoSpace = str_replace(' ', '', $disabled_functions);
$disFunctions = explode(',', $disFunctionsNoSpace);
$this->disFunctions = $disFunctions;
// get file content of the uploaded file (renamed NOT the temporary)
$cFile = file_get_contents($this->fileDestination, FILE_USE_INCLUDE_PATH);
$found = array();
foreach($this->disFunctions as $kkeys => $vvals)
{
if(preg_match('#'.$vvals.'#i', $cFile))
{
array_push($found, $vvals);
}
} // end foreach
} // end filterFile
$up = new uploadFiles($filename);
$fileterringFile = $up->filterFile();
print_r($fileterringFile);
var_dump($fileterringFile);
感谢您对的一贯支持
如果未找到匹配项,则$found
将更改为空字符串。你应该做的是:
$found = array();
foreach($this->disFunctions as $kkeys => $vvals)
{
if(preg_match('#'.$vvals.'#i', $cFile))
{
array_push($found, $vvals); // LINE 324
}
} // end foreach
print_r($found);
只需移除else即可。
我也会做简单的
$found[]=$vvals;
不需要array_push