简体   繁体   English

"PHP - 使用文本文件中的名称集显示目录"

[英]PHP - display directories using set of names from text file

There are more than 5 folders in the 'central' folder but I want to display only these 3 folders listed in this text file. “中央”文件夹中有超过 5 个文件夹,但我只想显示此文本文件中列出的这 3 个文件夹。

foldername.txt:文件夹名.txt:

  • folder1文件夹1<\/li>
  • folder2文件夹2<\/li>
  • folder3文件夹3<\/li><\/ul>

    Get the names:获取名称:

     $read = fopen('foldername.txt', 'r'); $getname = file_get_contents('foldername.txt'); fclose($read);<\/code><\/pre>

    Now I want to display each foldername from the textfile while preserving the 'sort by date modified'.现在我想显示文本文件中的每个文件夹名称,同时保留“按修改日期排序”。

     $folder = glob('C:\\xampp\\htdocs\\mysite\\central\/*', GLOB_ONLYDIR); array_multisort( array_map( 'filemtime', $folder ), SORT_NUMERIC, SORT_DESC, $folder );<\/code><\/pre>

    Tried this:试过这个:

     foreach($folder as $name){ $root = 'C:\\xampp\\htdocs\\mysite\\central\/'.$getname; echo 'This is wrong, I dont know what to put next'; }<\/code><\/pre>

    I'm more of a Pull Stack(pull from the web, stack in the file) right now so I'm still learning.我现在更像是一个拉栈(从网络上拉,堆在文件中),所以我还在学习。

    "

I was not clear with my objective but here's the solution.我不清楚我的目标,但这是解决方案。

$getname = file(foldername.txt); // contains the folder names
$implodegetname = implode(",",$getname); //array to string
    
$folder = glob('C:\xampp\htdocs\mysite\central/*{{$implodegetname}}', GLOB_ONLYDIR);
array_multisort(
array_map( 'filemtime', $folder ),
SORT_NUMERIC,
SORT_DESC,
$folder
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM