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

WBOY
Release: 2016-06-13 13:11:00
Original
903 people have browsed it

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

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/>";

}

}
?>


Copy after login


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

------解决方案--------------------
$search="/class/i"; //这样就可以了
------解决方案--------------------
glob("./*{$search2}*"); 也可以解决你的问题
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!