繁体   English   中英

如何在页面顶部赋予.php文件唯一名称,并在index.php文件上显示唯一名称

[英]How to give a .php file unique name at top of page, and display unique name on index.php file

我有一个问题,可能是一个简单的问题。 我想做的是能够在php代码区域的文件夹中的每个.php文件的顶部放置一个唯一的名称。 然后,我希望index.php文件上的脚本在该文件夹中查找,拉出在php代码每一页顶部找到的每个.php文件的唯一名称,并将它们显示在索引的列表中。 php页面。

我是否必须在页面顶部执行以下操作:

< ?
{{{{{uniquenamehere}}}}}
? >

如果是的话,在这里获取唯一名称并显示在index.php页面上的代码将是什么样?

预先感谢,让我知道我是否需要更清楚地说明问题。 抱歉,如果这是一个非常简单的问题,我很困惑!

编辑

使用以下答案时收到此警告:警告:file_get_contents(test.php)[function.file-get-contents]:无法打开流:/path/index.php中没有此类文件或目录

这是我正在使用的代码,

  <?php

// Scan directory for files
$dir = "path/";
$files = scandir($dir);

// Iterate through the list of files 
foreach($files as $file)
{
// Determine info about the file
$parts = pathinfo($file);

// If the file extension == php
if ( $parts['extension'] === "php" )
{
// Read the contents of the file
$contents = file_get_contents($file);

// Find first occurrence of opening template tag
$from = strpos($contents, "{{{{{");

// Find first occurrence of ending template tag
$to = strpos($contents,"}}}}}");

// Pull out the unique name from between the template tags
$uniqueName = substr($contents, $from+5, $to);

// Print out the unique name
echo $uniqueName ."<br/>";
}
}
?>

未经测试,但应该大致是这样的。

<?php

// Scan directory for files
$fileInfo = pathinfo(__FILE__);

$dir = $fileInfo['dirname'];
$files = scandir($dir);

// Iterate through the list of files
foreach($files as file)
{
  // Determine info about the file
  $parts = pathinfo($file);

  // If the file extension == php
  if ( $parts['extension'] == "php" )
  {
    // Read the contents of the file
    $contents = file_get_contents($file);

    // Find first occurrenceof opening template tag
    $from = strpos($contents, "{{{{{");

    // Find first occurrenceof ending template tag
    $to = strpos($contents,"}}}}}");

    // Pull out the unique name from between the template tags
    $uniqueName = substr($contents, $from+5, $to);

    // Print out the unique name
    echo $uniqueName ."<br/>";
  }
}

暂无
暂无

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

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