【发布时间】:2014-09-18 04:43:19
【问题描述】:
我不知道该使用什么标题,因为这是一种非常不寻常的情况。请让我解释一下。我有一个包含多个页面的网站,每个页面都有不同的元标记,例如标题、描述和关键字。所以我做了这个代码:
define('title', 0);
define('keywords', 1);
define('desc', 2);
$tags = array(
'index' => array('My site', 'php, tricks', 'My site about php'),
'about' => array('About', 'etc, about', 'About this site'),
'other' => array('Other', 'some, shit', 'Some other shit')
);
我的网站页面如下所示:mysite.com/index、mysite.com/about 等,因此,我有一个目录,其中包含所有名为 index.php、about.php 等的页面。因此,如果我想添加一个名为contact 的新页面,我必须创建一个名为contact.php 的文件并在我的数组中添加一个新行,如下所示:
$tags = array(
'index' => array('My site', 'php, tricks', 'My site about php'),
'about' => array('About', 'etc, about', 'About this site'),
'other' => array('Other', 'some, shit', 'Some other shit'),
'contact' => array('Contact', 'contact, whatever', 'Contact form')
);
到目前为止,这工作正常。但是,现在我有一组以column- 开头的页面,我希望它们自动添加标签,而无需在代码中添加更多行。像这样的:
$tags = array(
'index' => array('My site', 'php, tricks', 'My site about php'),
'about' => array('About', 'etc, about', 'About this site'),
'other' => array('Other', 'some, shit', 'Some other shit'),
$column_pages => array($col_title, $col_keywords, $col_desc)
);
我想我应该先扫描我的目录中的文件以获取名称,然后过滤那些以“column-”开头的文件:
$column_page = scandir("content");
foreach ($column_page as $value) {
if(preg_match("/column/i", $value)) {
$column_pages = $value;
}
}
但是在这之后我有点卡住了,我不知道如何走得更远。我现在该怎么办?
我需要的是,说白了就是扫描特定文件夹/目录中的所有文件名,检查其名称是否以column-开头,然后生成属性在PHP的帮助下自动进行
例如,假设到目前为止我有3个以“column-”开头的文件,它们是:column-news、column-variety和column-radio;我的预期结果与下面的代码完全一样:
$tags = array(
'index' => array('My site', 'php, tricks', 'My site about php'),
'about' => array('About', 'etc, about', 'About this site'),
'other' => array('Other', 'some, shit', 'Some other shit'),
'column-news' => array('News', 'some, news', 'Column with news'),
'column-variety' => array('News', 'some, variety', 'Column with variety'),
'column-radio' => array('News', 'some, radio', 'Column with radio')
);
谢谢。
【问题讨论】:
-
那么您到底在寻找什么...?你卡在哪里了,不清楚!
-
我被困在这一点上,因为我不能再进一步了。变量 $column_pages 应该为名称以 column- 开头的所有文件生成名称-
-
我编辑了我的问题,现在它更清晰了。