How To Break a File Path Name into Parts

Q

How To Break a File Path Name into Parts? - PHP Script Tips - Working with Directoris and Files

✍: FYIcenter.com

A

If you have a file name, and want to get different parts of the file name, you can use the pathinfo() function. It breaks the file name into 3 parts: directory name, file base name and file extension; and returns them in an array. Here is a PHP script example on how to use pathinfo():

<?php
$pathName = "/temp/download/todo.txt";
$parts = pathinfo($pathName);
print_r($parts);
print("\n");
?>

This script will print:

Array
(
    [dirname] => /temp/download
    [basename] => todo.txt
    [extension] => txt
)

2007-04-23, 5046👍, 0💬