查詢

PharFileInfo::getMetadata()函式—用法及示例

「 獲取Phar檔案的後設資料 」


函式名稱:PharFileInfo::getMetadata()

適用版本:PHP 5 >= 5.3.0, PHP 7, PHP 8

函式描述:獲取Phar檔案的後設資料

用法: PharFileInfo::getMetadata(): mixed

引數: 該函式沒有引數。

返回值: 返回Phar檔案的後設資料,型別為mixed。

示例: 假設我們有一個名為test.phar的Phar檔案,其中包含一個名為test.txt的檔案,並且在Phar檔案的後設資料中儲存了一些自定義的資訊。

$phar = new Phar('test.phar');
$fileInfo = $phar['test.txt'];

$metadata = $fileInfo->getMetadata();
var_dump($metadata);

輸出:

array(2) {
  ["author"]=>
  string(7) "John Doe"
  ["version"]=>
  string(5) "1.0.0"
}

在上面的示例中,我們首先建立了一個Phar物件,並使用檔名test.phar進行初始化。然後,我們使用檔案路徑$phar['test.txt']獲取了Phar檔案中的檔案test.txt的PharFileInfo物件。接下來,我們呼叫getMetadata()函式來獲取test.txt檔案的後設資料,並將結果儲存在變數$metadata中。

最後,我們使用var_dump()函式來顯示後設資料的內容。在這個示例中,後設資料是一個包含兩個鍵值對的關聯陣列,其中包含了作者和版本資訊。

補充糾錯
熱門PHP函式
分享連結