本文介绍了为foreach()提供的参数无效-使用Glob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
今天我的脚本有问题,我的脚本应搜索(.css文件)
Today i have a problem with my script, my script should search for (.css files)
我使用了以下代码:
- 搜索根文件夹中的所有子文件夹
- 将子文件夹的所有路径置于数组中
- 通过使用foreach(){glob ....},脚本应找到CSS文件的所有路径
这是我的代码:
$path = '';
$stack[] = $dir;
while ($stack) {
$thisdir = array_pop($stack);
if ($dircont = scandir($thisdir)) {
$i=0;
while (isset($dircont[$i])) {
if ($dircont[$i] !== '.' && $dircont[$i] !== '..') {
$current_file = "{$thisdir}/{$dircont[$i]}";
if (is_dir($current_file)) {
$path[] = "{$thisdir}/{$dircont[$i]}";
$stack[] = $current_file;
}
}
$i++;
}
}
}
$path[] = $dir;
foreach($path as $dirname){
$add = glob($dirname . '/*.css');
foreach($add as $file){
$code = file_get_contents($file);
$code_arab = arabicer($code);
file_put_contents($file,$code_arab);
}
}
启动脚本时,我发现一条减弱的消息:
When i start my script i found an waning message:
我确定我的数组不为空.
I'm sure my array is not empty.
那么,任何人都可以帮助我解决这个问题?
So, anyone can help me how to solve this problem ?
谢谢.
推荐答案
更改此内容:
$path[] = $dir;
foreach($path as $dirname){
$add = glob($dirname . '/*.css');
foreach($add as $file){
对此:
$path[] = $dir;
var_dump($path);
foreach($path as $dirname){
$add = glob($dirname . '/*.css');
var_dump($add);
foreach($add as $file){
我们不知道第131行是哪个,所以我不知道哪个foreach失败.
We don't know which line 131 is, so I don't know which foreach fails.
(我猜是第二个,因为第一个实际上是由$path[] = ..
强制排列的)
(I'm guessing the 2nd, because the first is practically forced to array by $path[] = ..
)
这篇关于为foreach()提供的参数无效-使用Glob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!