faqts : Computers : Programming : Languages : PHP : Function Libraries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

8 of 10 people (80%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How do I get the extension of a file already on the server?

Aug 24th, 2002 08:51
Dan Stockton, Chris Dennett, http://php.net/manual/en/function.pathinfo.php


pathinfo
(PHP 4 >= 4.0.3)

pathinfo -- Returns information about a file path
Description
array pathinfo ( string path)


pathinfo() returns an associative array containing information about 
path. The following array elements are returned: dirname, basename and 
extension.

Example 1. pathinfo() Example

<?php

$path_parts = pathinfo("/www/htdocs/index.html");

echo $path_parts["dirname"] . "\n";
echo $path_parts["basename"] . "\n";
echo $path_parts["extension"] . "\n";

?> 
 


Would produce:


/www/htdocs
index.html
html