我正在用PHP开发一个最小的博客系统,该系统应该通过扫描文件夹中的postX.txt文件来工作,然后显示从最新到最旧的每一篇文章。对于一篇博客文章,这很好:
http://pastebin.com/i3hiLWGd
post1.text包含类似以下内容:
<?php
$post_user="Frash23";
$post_title="loltitle 2";
$post_content="<p>lolcontent post 2</p>";
$post_info="lolinfo post 2";
?>
这会输出一篇正确的博客文章。以下代码没有:
http://pastebin.com/HdtgMBPV
正如您所看到的,它是添加了foreach的相同代码。回声$file1输出"post2.txt post1.txt",那么为什么这不起作用呢?所有变量(通过chrome的firebug克隆检查HTML)都不起作用。(即博客/用户//.png)。
有人知道我做错了什么吗?
来自文档:
给定一个包含文件或目录路径的字符串,此函数将返回尾部名称组件。
在您的情况下,"尾随名称组件"是file1.txt
,当您包含它时,您将.txt
添加到file1.txt.txt
中,但它找不到。
更换此
include "blog/posts/{$file1}.txt";
带有
include "blog/posts/{$file1}";
您声称$file1
确实包含扩展名为的文件名,然后使用
include "blog/posts/{$file1}.txt";
当不需要文件扩展名并且找不到该文件时,您会附加该文件扩展名。尝试:
include "blog/posts/{$file1}";
将其更改为
foreach (array_reverse(glob("blog/posts/*")) as $path1)
这个
foreach (glob("blog/posts/*") as $path1)