DirectoryIterator::getExtension

Gets the file extension

&reftitle.description; public `string` `DirectoryIterator::getExtension`

Retrieves the file extension.

&reftitle.parameters; &no.function.parameters;
&reftitle.returnvalues;

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

&reftitle.examples;

### `DirectoryIterator::getExtension` example

    <?php

    $directory = new DirectoryIterator(__DIR__);
    foreach ($directory as $fileinfo) {
        if ($fileinfo->isFile()) {
            echo $fileinfo->getExtension() . "\n";
        }
    }

    ?>

&example.outputs.similar;

    php
    txt
    jpg
    gz

&reftitle.notes;

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

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

&reftitle.seealso;

- `DirectoryIterator::getFilename`
- `DirectoryIterator::getBasename`
- `pathinfo`