【问题标题】:How do I hide the .php extension when listing files in php?在 php 中列出文件时如何隐藏 .php 扩展名?
【发布时间】:2020-07-27 09:27:32
【问题描述】:

我有以下代码来显示 php 文件夹中的文件。

<html>
<head>
<?php require '/opt/bitnami/apps/wordpress/htdocs/head.php';?>
</head>
<body>
<br>
<br>
<br>
<br>
<?php
  if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != ".."&& $file != "posts.php") {
        $thelist .= '<a href="'.$file.'">'.$file.'</a><hr>';
      }
    }
    closedir($handle);

  }
?>
<center>
<h1>files</h1>
<br>
<br>
<div style=background-color:white;color:black;>
<br>
<p1 style="font-size: 25px;"><?php echo $thelist;?></p1><br>

<hr>
</div>
</center>
</body>
</html>

所以,我不希望 .php 文件扩展名在列出时不显示。例如,如果有一个名为 test.php 的文件,我希望它只列出 test.php。我应该添加/更改什么代码才能使其正常工作?

感谢您的帮助。

【问题讨论】:

标签: php html css file


【解决方案1】:

您可以尝试使用 str_replace()

str_replace(".php","",$file);

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-14
  • 1970-01-01
  • 2011-09-08
  • 2012-01-12
  • 1970-01-01
  • 2012-04-19
  • 1970-01-01
相关资源
最近更新 更多