Splitting a File Path Name into Parts in PHP


How To Break a File Path Name into Parts in PHP?

✍: FYIcenter.com


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():

$pathName = "/temp/download/todo.txt";
$parts = pathinfo($pathName);

This script will print:

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


Processing Web Forms in PHP

Retrieving Directory Name from File Path Name in PHP

Working with Directories and Files in PHP

⇑⇑ PHP Tutorials

2016-11-17, 3765🔥, 0💬