2015-04-28 65 views
0

如何删除最后一个斜线之前的点?删除点获取目录中的文件列表

例与HTML表格点输出:

Name        Type   Size  Last Modified 
http://www.airsahara.in./fares/  text/x-php 662  2014-09-04 
http://www.airsahara.in./   text/x-php 1681  2014-09-04 

这里是PHP代码我有,让我仅根据什么是忽略数组中读取特定的目录。我只是不知道如何摆脱.之前的尾部斜杠/

我需要删除该点,以便网址可以正确。

<? 
$ignore = array('images', 'css', 'includes', 'cgi-bin', 'xml-sitemap.php'); 

    function getFileList($dir, $recurse=false) { 
    global $ignore; 

    $retval = array(); 

    // open pointer to directory and read list of files 
    $d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading"); 
    while (false !== ($entry = $d->read())) { 

     // Check if this dir needs to be ignored, if so, skip it. 
     if (in_array(utf8_encode($entry), $ignore)) 
      continue; 

     // skip hidden files 
     if($entry[0] == ".") continue; 
     if(is_dir("$dir$entry")) { 
     $retval[] = array(
      "name" => "$dir$entry/", 
      "type" => filetype("$dir$entry"), 
      "size" => 0, 
      "lastmod" => filemtime("$dir$entry") 
     ); 
     if($recurse && is_readable("$dir$entry/")) { 
      $retval = array_merge($retval, getFileList("$dir$entry/", true)); 
     } 
     } elseif(is_readable("$dir$entry")) { 
     $retval[] = array(
      "name" => "$dir", 
      "type" => mime_content_type("$dir$entry"), 
      "size" => filesize("$dir$entry"), 
      "lastmod" => filemtime("$dir$entry") 
     ); 
     } 
    } 
    $d->close(); 

    return $retval; 
    } 

    $dirlist = getFileList("./", true); 

    // output file list in HTML TABLE format 
    echo "<table border=\"1\">\n"; 
    echo "<thead>\n"; 
    echo "<tr><th>Name</th><th>Type</th><th>Size</th><th>Last Modified</th></tr>\n"; 
    echo "</thead>\n"; 
    echo "<tbody>\n"; 
    foreach($dirlist as $file) { 
     if($file['type'] != 'text/x-php') continue; 
    echo "<tr>\n"; 
    echo "<td>http://www.airsahara.in{$file['name']}</td>\n"; 
    echo "<td>{$file['type']}</td>\n"; 
    echo "<td>{$file['size']}</td>\n"; 
    echo "<td>",date('Y-m-d', $file['lastmod']),"</td>\n"; 
    echo "</tr>\n"; 
    } 
    echo "</tbody>\n"; 
    echo "</table>\n\n"; 
?> 

回答

2

你可以执行字符串替换 -

"name" => str_replace('./','/', $dir), 
+0

这是太简单了。谢谢。认为这是最合乎逻辑的方法吗? – Mike

+0

不知道这些名字是如何形成的,我会说这是最合乎逻辑的。 –

+0

谢谢。我总是看着明显的做事方式。 – Mike

相关问题