Home  >  Article  >  Backend Development  >  遍历资料并且匹配文件名的时候出错.

遍历资料并且匹配文件名的时候出错.

WBOY
WBOYOriginal
2016-06-13 13:11:00904browse

遍历文件并且匹配文件名的时候出错................

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php $search="'/class/i'";
$dir=opendir("./");
$filearray=array();
while(($file=readdir($dir))!==false)
{
$filearray[]=$file;
}
foreach($filearray as $value)
{
if(preg_match_all([color=#FF0000]$search[/color],$value,$filefinal))
{
echo "符合搜索的文件名:".$value."<br/>";

}

}
?>




出错部分已经用红色标注,改成'/class/i'之后又能正常...难道preg_match_all这个函数的参数不可以用变量吗????

------解决方案--------------------
$search="/class/i"; //这样就可以了
------解决方案--------------------
glob("./*{$search2}*"); 也可以解决你的问题
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn