SplFileInfo::getExtension

(PHP 5 >= 5.3.6, PHP 7, PHP 8)

SplFileInfo::getExtensionGets the file extension

說(shuō)明

public SplFileInfo::getExtension(): string

Retrieves the file extension.

參數(shù)

此函數(shù)沒(méi)有參數(shù)。

返回值

Returns a string containing the file extension, or an empty string if the file has no extension.

范例

示例 #1 SplFileInfo::getExtension() example

<?php

$info 
= new SplFileInfo('foo.txt');
var_dump($info->getExtension());

$info = new SplFileInfo('photo.jpg');
var_dump($info->getExtension());

$info = new SplFileInfo('something.tar.gz');
var_dump($info->getExtension());

?>

以上例程會(huì)輸出:

string(3) "txt"
string(3) "jpg"
string(2) "gz"

注釋

注意:

Another way of getting the extension is to use the pathinfo() function.

<?php
$extension 
pathinfo($info->getFilename(), PATHINFO_EXTENSION);
?>

參見(jiàn)