簡體   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