我正在构建一个返回字符串的类,该字符串将自动包含文件夹中的文件,有点像 HTML 文件的加载器。
这是将被调用的方法:
function build_external_file_include($_dir){
$_files = scandir($_dir);
$_stack_of_file_includes = "";//will store the includes for the specified file.
foreach ($_files as $ext){
//split the file name into two;
$fileName = explode('.',$ext, 1);//this is where the issue is.
switch ($fileName[1]){
case "js":
//if file is javascript
$_stack_of_file_includes = $_stack_of_file_includes."<script type='text/javascript' src='".$dir.'/'. $ext ."'></script>";
break;
case "css";//if file is css
$_stack_of_file_includes = $_stack_of_file_includes."<link rel=\"stylesheet\" type=\"text/css\" href=\"".$dir.'/'. $ext."\" />";
break;
default://if file type is unkown
$_stack_of_file_includes = $_stack_of_file_includes."<!-- File: ". $ext." was not included-->";
}
}
return $_stack_of_file_includes;
}
所以,这运行没有任何错误。但是,它没有做它应该做的事情……或者至少我打算做的事情。这里从技术上讲,
$fileName[1]
应该是扩展js
$fileName[0]
应该是文件名main
但
$fileName[0]
是main.js
。
爆不认.
?
先感谢您。