【发布时间】:2014-07-21 02:13:36
【问题描述】:
在index.php 中,虽然名称可以是任何名称,但我现在在最顶部有一个数组,仅用于测试目的。
<?php
$settings = array(
enabled => true,
id => "KMS",
theme=>"kms_standard",
);
?>
我开始将其用作在我的 CMS 表中使用的信息。基本上我正在扫描页面和其他目录的主目录。然后我将li 回显到显示信息的“表格”中,尽管我需要的信息不仅仅是创建/编辑的日期。
前:
Page Name | Identifier | Status | Theme | Created/Edited
index.php CMS Enabled Dark 12/12/12 12:00
要获得创建/编辑的日期,我使用date('l jS \of F Y h:i:s A',filemtime('../'.$page))
有没有办法为文档设置这样的数据然后获取它,如果没有,我将如何在每个循环中使用数组而不包括整个文件。我相信如果我这样做 include($file) 它将解析所有 HTML 和 PHP,但我只需要该页面中的 $settings 变量。我希望我让自己足够清楚。如果不是下面的例子
function is_dir_empty($dir) {
if (!is_readable($dir)) return NULL;
$handle = opendir($dir);
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
return FALSE;
}
}
return TRUE;
}
$pages = scandir('../',0);
foreach($pages as $page){
if(is_dir('../'.$page) && !is_dir_empty('../'.$page)){
//iterate deeper to get these files as well
}elseif(!is_dir('../'.$page)){
$file = get_file('../'.$page);//basically get the array of information some how
echo '<div class="row" id="'.removeExtensions($page).'"><ul>'.
'<li class="fifths"><div class="checkbox_container">'.
'<input type="checkbox" id="'.$kpage.'_check" value="'.$page.'" class="checkbox" name="delete_page[]" />'.
'<label for="'.$kpage.'_check"><span></span></label></div>'.$kpage.'</li>'.
'<li class="fifths">'.$file['id'].'</li>'.
'<li class="fifths">'.$file['enabled'].'</li>'.
'<li class="fifths">'.$file['theme'].'</li>'.
'<li class="fifths" title="'.date('l jS \of F Y h:i:s A',filemtime('../'.$page)).'">'.date('l jS \of F Y h:i:s A',filemtime('../'.$page)).'</li></ul></div>';
}
}
更新以供将来参考 效果很好
JSON
{
"index.php":{
"enabled":"true",
"theme":"dark",
"identifier":"KMS"
}
}
仪表板
$jsona = file_get_contents("../pages.json");
$jsonb = json_decode($jsona,true);
$data = $jsonb['pages'];
【问题讨论】: