【发布时间】:2016-05-22 01:54:37
【问题描述】:
不久前,我发了一篇文章 (Searching for a specific string from all PHP files in the parent directory),内容是关于我在数组中查找文件路径的位置,前提是文件具有特定的关键字。
但是,那是在我的旧网站中,我现在已经丢失了。所以我目前正在重新创建它。但是,由于某种原因,此功能不起作用。
public function build_active_theme() {
$dir = CONPATH . '/themes/' . $this->get_active_theme() . '/';
$theme_files = array();
foreach(glob($dir . '*.php') as $file) {
$theme_files[] = $file;
}
$count = null;
foreach($theme_files as $file) {
$file_contents = file_get_contents($file);
if(strpos($file_contents, 'Main')) {
$array_pos = $count;
$main_file = $theme_files[$array_pos];
echo $main_file;
}
$count++;
}
}
此函数导致以下错误:
注意:未定义索引:在 /home/u841326920/public_html/includes/class.themes.php 第 30 行
我已将问题的范围缩小到 $count 变量的问题。一旦脚本找到正确的文件,每当我尝试回显 $count 值时,什么都不会显示。
但是在这样一个简单的问题上花了将近一个小时后,我显然开始感到沮丧,所以我现在正在寻求帮助。
(注意:我直接将旧帖子中的函数复制到我的代码中,并对变量进行了适当的更改以在新站点中“工作”,因此它与修复我的解决方案几乎完全相同以前的问题 - 有趣的是,这也是由 $count 变量引起的)。
谢谢, 基隆
【问题讨论】:
标签: php loops count themes frontend