文件夹
File1.txt
File2.txt
File3.txt
File4.txt
File5.txt
File6.txt
File7.txt
File8.txt
File9.txt
但是每当我添加另一个文件时,它看起来都像这样
File1.txt
File10.txt //新文件
File2.txt
File3.txt
File4.txt
File5.txt
File6.txt
File7.txt
File8.txt
File9.txt 也许我添加了另一个文件
File1.txt
File10.txt //新文件
File11.txt //新文件
File2.txt
File3.txt
File4.txt
File5.txt
File6.txt
File7.txt
File8.txt
File9.txt
您可以猜到我何时将所有这些文件包含在一个PHP文件中 搞砸了...
假设file1.txt的内容为:1
File10.txt的内容为:10
File2.txt的内容为:2
File3.txt的内容为:3
依此类推
当我添加此内容时,页面上的订单将显示为
1
10
2
3
4
5
依此类推
那么我如何使文件按数字顺序显示??
这是我正在使用的代码
<?php
// Add correct path to your countlog.txt file.
$path = 'ChatNumbers.txt';
// Opens countlog.txt to read the number of hits.
$file = fopen( $path, 'r' );
$count = fgets( $file, 1000 );
fclose( $file );
// Update the count
$count = abs( intval( $count ) ) + "1";
// Opens countlog.txt to change new hit number.
$file = fopen( $path, 'w' );
fwrite( $file, $count);
fclose( $file );
$ab = 'Chat_';
$cn = "$count";
$rp = '.html';
$fr = "$ab$cn$rp";
$path = "Chats/$fr";
if (isset($_POST['field1'])) {
$fh = fopen($path,"a+");
$string = $_POST['field1'].'<p></p>';
fwrite($fh,$string); // Write information to the file
fclose($fh); // Close the file
}
?>
这就是我目前包含文件的方式
<php
foreach (glob("chat/Chats/*.html") as $filename)
{
include $filename;
}
?>
答案 0 :(得分:0)
我确定这不是解决所有问题的最佳方法,但是要回答这个问题,您需要(自然)排序:
$files = glob("chat/Chats/*.html");
natsort($files);
foreach ($files as $filename)
{
include $filename;
}