PHP – Parse Filenames and Paths with pathinfo()

The pathinfo() function allows you to turn a filepath into an Array and then interact with the keys of the Array. You can grab the Filename, Extension, Folder Name and Basename.

pathinfo()

pathinfo.php

<?php

$filepath = "./folder/file.txt";

$filepathArray = pathinfo($filepath);

var_dump($filepathArray);
echo "<br><br>";
echo $filepath;
echo "<br>";
echo $filepathArray['dirname'];
echo "<br>";
echo $filepathArray['basename'];
echo "<br>";
echo $filepathArray['filename'];
echo "<br>";
echo $filepathArray['extension'];

?>

Be the first to comment

Leave a Reply